Geeks With Blogs

News

Google My Blog

Catch me at: The List!


My InstallScript Utility Belt My Amazon Wishlist
My Standard Disclaimer


Archives
Chris G. Williams Beware: I mix tech and personal interests here.

One of the things I mention in my CodeCamp talk is why you should instantiate your objects before passing them in as params. I was surprised to find out most people in my sessions had never realized why...

Look at it like this:

myObj.SomeMethod(new OtherObject(param1, param2), variable, variable)

By doing the above, instead of creating a variable to contain OtherObject and passing the variable in, you lose the ability to Dispose of it when you are done. Garbage Collection will grab it eventually of course, but this is horribly inefficient.

Do this instead:

dim oObject as new OtherObject(param1, param2)
myObj.SomeMethod(oObject, variable, variable)
 ...
 ...
oObject.dispose
myObj.dispose

Posted on Tuesday, May 3, 2005 10:31 AM Game Development , General Interest | Back to top


Comments on this post: Be nice to your Garbage Collector, your users will thank you

# re: Be nice to your Garbage Collector, your users will thank you
Requesting Gravatar...
Actually, the using() statement is appropriate here. What if the "SomeMethod" throws an exception or a "ThreadAbortException" happens? Indeterministic cleanup is what happens.
Left by Dave Gladfelter on May 03, 2005 1:24 PM

Your comment:
 (will show your gravatar)


Copyright © Chris G. Williams | Powered by: GeeksWithBlogs.net