Re: Setting objects to Nothing uses less memory!
vdex42_at_hotmail.com
Date: 08/19/04
- Next message: Chris Lyon [MSFT]: "Re: Setting objects to Nothing uses less memory!"
- Previous message: Chris Lyon [MSFT]: "RE: Setting objects to Nothing uses less memory!"
- In reply to: Chris Lyon [MSFT]: "RE: Setting objects to Nothing uses less memory!"
- Next in thread: Chris Lyon [MSFT]: "Re: Setting objects to Nothing uses less memory!"
- Reply: Chris Lyon [MSFT]: "Re: Setting objects to Nothing uses less memory!"
- Messages sorted by: [ date ] [ thread ]
Date: 19 Aug 2004 13:51:53 -0700
Hi Chris,
Thanks for replying.
Do I understand correctly:
When the system reaches the end of the function that doesn't do the set
object to nothing: The garbage collector only does one pass and frees
"bigObjects", but does not recursively free anything it owns? (i.e.
that only happens in the second pass)
But when the system reaches then end of the function that sets
everything to nothing at the end: The garbage collector frees
"bigObjects" and its internal instance of "lotsOfData" in the first
pass , because I have explicitly forced the internal references to be
lost with my "InternalSetNull" function?
Thanks,
Ivan
"Chris Lyon [MSFT]" wrote:
> Hi Ivan
>
> I think people often get confused about setting references to null.
There is no hard rule that setting things to null will always or never
release memory sooner. In your code
> snippets, you're demonstrating a good example of when to set things
to null/Nothing, but maybe not how you expected.
>
> The key is your InternalSetNull() method. In the first example,
you're keeping your ReallyBigObjects references, which in turn keep
references to lotsOfData. By setting
> lotsOfData to null, you're telling the GC that you no longer need it,
but you still want to keep around your ReallyBigObjects. The GC will
then collect the lotsOfData arrays when it
> performs its next collection, but not necessarily your
ReallyBigObjects (since lotsOfData is really where the memory pressure
is coming from).
>
> So to sum up, setting instance variables to null has the effect
you're expecting (free memory sooner), while setting local variables to
null has little effect.
>
> Hope that makes sense!
> -Chris
>
- Next message: Chris Lyon [MSFT]: "Re: Setting objects to Nothing uses less memory!"
- Previous message: Chris Lyon [MSFT]: "RE: Setting objects to Nothing uses less memory!"
- In reply to: Chris Lyon [MSFT]: "RE: Setting objects to Nothing uses less memory!"
- Next in thread: Chris Lyon [MSFT]: "Re: Setting objects to Nothing uses less memory!"
- Reply: Chris Lyon [MSFT]: "Re: Setting objects to Nothing uses less memory!"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|