<p>In a VB6 application, I have a <code>Dictionary</code> whose keys are <code>String</code>s and values are instances of a custom class.  If I call <code>RemoveAll()</code> on the <code>Dictionary</code>, will it first free the custom objects?  Or do I explicitly need to do this myself?</p>

<pre><code>Dim d as Scripting.Dictionary

d("a") = New clsCustom
d("b") = New clsCustom

' Are these two lines necessary?
Set d("a") = Nothing
Set d("b") = Nothing

d.RemoveAll
</code></pre>

[{'answer_id': 75066, 'author': 'Neil C. Obremski', 'author_id': 9642, 'author_profile': 'https://Stackoverflow.com/users/9642', 'pm_score': 3, 'selected': True, 'text': '<p>Yes, all objects in the <code>Dictionary</code> will be released after a call to <code>RemoveAll()</code>.  From a performance (as in speed) standpoint I would say those lines setting the variables to <code>Nothing</code> are unnecessary, because the code has to first look them up based on the key names whereas <code>RemoveAll()</code> will enumerate and release everything in one loop.</p>\n'}, {'answer_id': 75073, 'author': 'Chris Smith', 'author_id': 9073, 'author_profile': 'https://Stackoverflow.com/users/9073', 'pm_score': 2, 'selected': False, 'text': '<p><code>RemoveAll</code> will remove all the associations from the <code>Dictionary</code>: both the keys and values. \nIt would be a reference leak for the <code>Dictionary</code> to keep a reference to the values in the <code>Dictionary</code>.</p>\n'}, {'answer_id': 75107, 'author': 'palehorse', 'author_id': 312, 'author_profile': 'https://Stackoverflow.com/users/312', 'pm_score': 0, 'selected': False, 'text': '<p>If there are no other variables that reference the items in the collection then those objects should be handed to the Garbage Collector to be cleaned up the next time the GC is run.</p>\n\n<p>If you, for example do this where sObj is a static variable somewhere then the when the GC is invoked next by the system, the first object will be cleaned up but the second which still is referenced by sObj will not.</p>\n\n<pre><code>d("a") = New clsCustom\nd("b") = New clsCustom code.\nsObj = d("b")\n\nd.RemoveAll()\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/75011', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/863/']