Enginuity's memory manager

Started by
9 comments, last by fallenang3l 20 years, 8 months ago
I have read most of the "Discuss this article" thread and correct me if I'm wrong but there is a redone IMMObject class.

fallenangel - Here is my arguement, clearly logical. The constructor for the IMMObject class is this:

IMMObject::IMMObject()
{
liveObjects.push_back(this);

//update the constructor to initialise refCount to zero
refCount=0;
}

So *automatically* the item is placed on the list of "live" objects. Are you following me thus far?

Now naturally the item has refCount set to 0, meaning that the next time we clean out the garbage, this function is going to put it in its dead list when Release is called:

void IMMObject::Release()
{
--refCount;
if(refCount<=0)
{
liveObjects.remove(this);
deadObjects.push_back(this);
}
}

Are you with me? So right now, after our Release() function is called, or object is placed on the dead objects list. Now, it is only a matter of time before this function gets called, THUS DELETING the object regardless if its located on the stack. Look here:

void IMMObject::CollectGarbage()
{
for(std::list::iterator it=deadObjects.begin(); it!=deadObjects.end(); it++)
{
delete (*it);
}
deadObjects.clear();
}

Even if for some reason the stack located object is not ever placed on the dead objects list (which would make sense because who in their right mind is going to call Release() on a stack located object?), it will *still* get deleted when this function is called:

void IMMObject::CollectRemainingObjects(bool bEmitWarnings)
{
CollectGarbage();
for(std::list::iterator it=liveObjects.begin();it!=liveObjects.end();it++)
{
IMMObject *o=(*it);
if(bEmitWarnings)
{
//log some kind of error message here
//we'll be covering how to log messages later this article
}
delete o;
}
liveObjects.clear();
}

Eventually, nomatter what the circumstance of the refcount variable is, if a stack located object which inherits the IMMObject class is used, it will eventually be deleted.

Also, I HAVE TRIED IT. I got the same exact results I am talking about.

Now PLEASE, if I am wrong I desperatly want to find out, PLEASE show me where I am wrong. I think it has to have something to do with this "auto" operator so I am going to look it up. Which specific page/function/line can I look at which will show me how this stops the object from being put on the live objects list, because to me it looks like the constructor puts it there nomatter what.

[edited by - 31337 on July 27, 2003 12:32:28 AM]
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/

This topic is closed to new replies.

Advertisement