New without Delete workinf fine

Problems building or running the engine, queries about how to use features etc.
laweya
Kobold
Posts: 28
Joined: Mon Jan 17, 2005 3:48 pm
Location: Kenya

New without Delete workinf fine

Post by laweya »

I have been programming in c++ for a while but I'm fairly new to 3d programming. Going through Ogre's tutorials, I realised that there are objects created using "new" but are not released using "delete", I have the directx SDK on debug which really complains on memory leaks but I get none when I compile and run the tutorials, how is this possible? When I try to delete the objects, my program crashes.
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8

Post by haffax »

Can you be more specific about the created objects? Maybe show us the code lines.
There are methods that destroy certain data. For instance SceneManager::clearScene() implicitly deletes all SceneNodes. And most Managers delete all data they are responsible for in their destructors. All this behaviour is described in the corresponing API documentation.
team-pantheon programmer
creators of Rastullahs Lockenpracht
laweya
Kobold
Posts: 28
Joined: Mon Jan 17, 2005 3:48 pm
Location: Kenya

Which classes get cleaned up and which ones don't?

Post by laweya »

It makes sense if you put it that way, but how do you know whether your class will be cleaned up by the code, e.g. The Lights Camera Action tutorial has instances of LightFlasherControllerFunction and LightBlinker classes and I think they get automatically cleaned up.
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8

Post by haffax »

The ControllerManager destructor calles clearControllers() which deletes all registered controllers. I don't know the tutorial, so I cannot help with the other classes' intsances you list here.
team-pantheon programmer
creators of Rastullahs Lockenpracht
guts
Gnoblar
Posts: 24
Joined: Thu Oct 28, 2004 3:18 pm

Post by guts »

and I think it's the same with Listeners ... maybe these classes should be SharedPointers, so that it's obvious that you do not have to delete them?

PS: Sorry for all my "you could change this" topics on your forum *gg*
it's just because i'm writing my own engine, but really like ogre's design (that's why i adapted some of it in my engine :D)
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 67

Post by sinbad »

Listeners do have to be deleted, actually - that's because you create them. The rule is that if your code performs the new, it has to perform the delete. Shared pointers are a special case.

All the 'new' entries you saw were Ogre; in places like createEntity etc. Ogre manages the destruction of those objects so the user doesn't have to worry about it. They are being delete'd inside Ogre.