Code: Select all
SomeType* obj->createSomeObj(); //! It mean 'new' or 'smgr->add' etc..
obj->delete();
if(obj) obj->doSmth()...
That code will not fails but...
If our object have getReferenceCount()>1 it'll NOT WILL BE DELETED and
we can have memory leak..
Well just define this:
Code: Select all
#define KILL(irrobject) \
{\
if(irrobject)\
{\
s32 ref=irrobject->getReferenceCount();\
while(--ref>0) irrobject->drop();\
irrobject->remove(),irrobject=NULL;\
}\
}
An improve that KILL macros is preventing "not exist object" error's type.
(Usual if you drop,remove or delete an object and call it later you'll got one.)
Now don't worry of it just do simple check in your code:
Code: Select all
SomeType* obj->createObj;
KILL(obj)
.........
//! Even if we KILL somewhere our object yet.
//! Doing a simple check:
if(obj) obj->doSmth();
And of course you must not use KILL(object) if your code
still needs an object. If you used object->grab() etc..
Sorry for my bad english, friends.