🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Question about destruction of objects

Started by
0 comments, last by WitchLord 9 years, 6 months ago

Following on from some questions I asked in this thread:

http://www.gamedev.net/topic/663007-yet-another-performance-comparison-as-vs-small/

I have searched in the manual, but there is one thing that I still can't clarify: For reference based objects, will the destructor (if registered) be called immediately after the final Release call, or will it be called via the garbage collector? In other words does the garbage collector just do the memory freeing, or does it also do the object destruction?

Thanks

Advertisement

It is the Release call that calls the destructor and frees the memory when the refcounter reaches 0.

The garbage collector is only there to help resolve circular references, i.e. when the refcounter would never reach 0 under normal circumstances. The side effect of this is that the garbage collector has to hold a reference on its own for objects that may form circular references. When the garbage collector sees that the refcount is 1, it can immediately release its reference and thus destroy the object without further checks.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement