deleting pointers

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
User avatar
Shinobi
Kobold
Posts: 27
Joined: Thu Dec 16, 2004 5:01 pm
Contact:

deleting pointers

Post by Shinobi »

I need to know which pointers i have to delete.

I've readen in a post that i have to delete scenenodes. Is that right?

What pointers do i have also to destroy!

(a complete list if possible ;) )


thx in advance
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

If all you ever use are the 'create' methods in Ogre, all you have to do is delete Root (or make it go out of scope if you stored it by value).

You only have to delete things that you 'new' yourself. You never have to delete scene nodes, and you shouldn't try to (it will crash). OGRE manages everything it 'new's.
User avatar
Shinobi
Kobold
Posts: 27
Joined: Thu Dec 16, 2004 5:01 pm
Contact:

Post by Shinobi »

thx

and good to know

it knows... ehmm 'new's :D
User avatar
Devil N
Greenskin
Posts: 123
Joined: Sun Jun 26, 2005 4:32 pm
Location: Groningen, The Netherlands
Contact:

Post by Devil N »

If you are ever in doubt, you can also just run your program and check the OgreLeaks.log file afterwards. As far as I can tell, Ogre does a pretty good job at detecting memory leaks.
User avatar
Aklix
Goblin
Posts: 222
Joined: Mon Dec 27, 2004 5:21 am
Contact:

Post by Aklix »

For added accuracy, there are many profilers listed here.
User avatar
Yavin
Bronze Sponsor
Bronze Sponsor
Posts: 140
Joined: Wed Mar 02, 2005 3:41 pm
Location: Lake Constance, Germany
Contact:

Post by Yavin »

What about the shared pointers? If I forget to decrement a manually incremented usage count does ~Root() free this objects?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Unlike COM (<cough>garbage<cough>) our shared pointers decrement automatically so you don't have to worry about manually decrementing them. You cannot manually increment them (nor should you ever need to). You do have to make sure your pointers go out of scope before you shutdown Root though, the result of not doing this is an assert.
User avatar
Yavin
Bronze Sponsor
Bronze Sponsor
Posts: 140
Joined: Wed Mar 02, 2005 3:41 pm
Location: Lake Constance, Germany
Contact:

Post by Yavin »

sinbad wrote:You do have to make sure your pointers go out of scope before you shutdown Root though, the result of not doing this is an assert.
But only in debug mode, isn't it? Thanks.

Why I'm asking this? The problem is, that we have to put the smart pointers on the heap to use them in JNI or increment the usage count manually because of passing the Object pointer into Java. If a lazy programmer doesn't call the dispose function of each Java object, the usage count will not be decremented and/or smart pointers on the heap are not deleteted.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Yavin wrote:
sinbad wrote:You do have to make sure your pointers go out of scope before you shutdown Root though, the result of not doing this is an assert.
But only in debug mode, isn't it? Thanks.
Well yeah, but that's why you run everything in Debug mode first, right? Once you realise you made a mistake, you fix it so it'll never occur in Release.
User avatar
Yavin
Bronze Sponsor
Bronze Sponsor
Posts: 140
Joined: Wed Mar 02, 2005 3:41 pm
Location: Lake Constance, Germany
Contact:

Post by Yavin »

sinbad wrote:Well yeah, but that's why you run everything in Debug mode first, right? Once you realise you made a mistake, you fix it so it'll never occur in Release.
You take the point :wink:
Post Reply