ivansafrin/Polycode — pull request #94 by mcclure (2012-03-05 08:07:35+00:00)
Title: Memory leak fixes

Went looking for memory leaks in Polycode. Found a LOT.

In this pull request, I broke my changes into four commits because some of the changes I made seemed "controversial" and I wanted you to have the ability to take or leave some of them.

Commit 1: Basic no-brainer leak fixing

Commit 2: Virtual destructors. IMO basically every destructor in Polycode should be virtual because any class could potentially be subclassed by a Polycode user, and I ran into situations even in basic Polycode where destructors weren't being called (and memory was leaking) for lack of virtualness. I did NOT virtualize the following classes: particle , quaternion, vertex, matrix4, String, Data; because I figured (1) these objects are getting created in mass quantities (2) these objects are often really tiny, so there is some reason to think there's actually a real downside to giving those classes a vtable.

Commit 3: A few objects had owned variables which sometimes, but not always, might be appropriate to outlive the object. For example a Scene has many children and a default camera. Looking at the destructor I find commented out code to delete all the children. Instead of commenting it out, I added an "ownsChildren" flag and it deletes or doesn't depending on whether the flag says to. This means the user can actually decide which behavior they want. Also impacted here: Screen, SceneMesh (because sometimes it owns its Skeleton and sometimes it doesn't).

Commit 4: As part of the virtual destructors patch PhysicsSceneEvent needed to be modified, but the patch didn't apply because the commit I was branching from didn't include pull request #90, so I just went ahead and added a tiny commit adding a "virtual" to #90.

Note: I looked at the CollisionScene classes, but not the PhysicsScreen or PhysicsScreen classes yet. I feel confident the latter two will also have lots of leaks.