Leaders quwiltw Posted January 7, 2003 Leaders Posted January 7, 2003 Anyone got any thoughts on setting their object references to nothing? I've found conflicting information on the subject: some say that the garbage collector is smart enough to clean up our mess and others say to use the old Set objXXX = Nothing like VB6. So far I've been safely assuming the former is correct, but just wondered if anyone has found different? Quote --tim
*Gurus* divil Posted January 7, 2003 *Gurus* Posted January 7, 2003 The short answer is yes, it's clever enough. As soon as the variable goes out of scope it is essentially set equal to nothing anyway, as it was in COM and VB6. The only possible advantage is that the GC *might* release it slightly sooner. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Bucky Posted January 7, 2003 *Experts* Posted January 7, 2003 I've been wondering, when using GDI+ objects such as brushes and pens, do you have to call the Dispose method of each one when their use is finished to free up memory, or does the GC dispose them automatically when they go out of scope? Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
*Gurus* divil Posted January 7, 2003 *Gurus* Posted January 7, 2003 GC will clean them up fine, but it's often preferable to .Dispose them yourself, and it's good practice. But it doesn't actually make much of a difference :) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Nerseus Posted January 7, 2003 *Experts* Posted January 7, 2003 Some objects you MUST call Dispose on yourself, to free memory. Things like DeviceContexts come to mind though I haven't used them in .NET. I know Graphics objects that you create must be disposed (not the ones passed in as an argument to a Paint event). I suspect that the Graphics object is creating a DeviceContext behind the scenes. If you don't call Dispose it doesn't get released til the Garbage Collector runs (and maybe not even then). There are other things to be aware of when using Dispose, especially if you create your own object. Read through the help on it to get more info. -n Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.