Look for confirmation dealing with Garbage Cleanup

Not a real issue here, just wanted to confirm something about Lights and mention something else. I was using the Session Panel to view my Scene Graph as I deleted an entire level (in other words I ran a cleanup on a level).

The entire level did disappear from around my character and I could see the Nodes disappear from the Scene graph.

I noticed one thing… My character was still receiving light from the light nodes. I even looked through my Scene Graph to confirm some light Nodes were still there.

Ok… So, I decided to kill the lights on my main character.

maincharacter.setLightOff(somelightNodePath);

After setting all lights to off for my Main Character, I ran my cleanup test again. This time I noticed the light nodes were NOT in the Scene Graph.

And that’s what I want to confirm; must lights be turned off for every object within the class in order to correctly garbage collect them? My test says yes, but I want to get a few more opinions. I know you can’t leave a reference behind for anything, but I didn’t think the setOff or On for lights would count as one.

Aside from the lights, I do like the fact overall game memory did not increase when I dumped the first level and created a different one by creating a new level’s instance.

One thing is bothering about this memory management with P3D. Even if you successfully dump resources, delete all of a class’s attributes and remove all running tasks… The instance of that class will still remain.

It’s not like you called a del statement on the instance itself.

class Human(ShowBase):
	def __init__(self):
		self.name = "morgan"

Thief = Human()

You would think an instance of an object class would be totally deleted once you call del on the instance directly, after you’ve done your garbage collecting, as in.

del Thief

Otherwise you have an instance that has been cleanup up of resources, but the scope of the instance is still around. I’m not even sure if a del self call would work after a garbage collection, but I include it anyway.

At least I’m not seeing a memory spike, so I’m not going to pull my hair out just yet. I’ll wait until I see the game memory constantly increasing without freeing up after my garbage collecting from level to level.

I guess if I can see all the right Nodes delete from my scene graph, I should consider that a win with garbage collecting.

Any takers on this thought?

I think I’ve made the correct changes now. Wasn’t quite doing things the way I should have been on the cleanup, but thanks to some good research, I believe it’s a done deal.

Hopefully. :smiley:

In general, you have to remove all references to an object before that object will be deleted. This includes detaching lights from nodes that reference them. “del obj” doesn’t actually delete the object; it’s thus unlike the C++ delete operator; all it does is delete the reference “obj”. Thus, “del self” is always meaningless.

It’s both a curse and a blessing of Python’s reference-counting memory management. The blessing is that you don’t have to think (much) about it. The curse is that you don’t have much control over it.

David

I just have one more worry…


PhePalOuter2 = PhePalOut2();


def MakeMe(PhePalOuter2):
    PhePalOuter2.destroy();
    del PhePalOuter2;
    ObjPhe.CurrentArea = "AbusNecro";
    AbusNecro = AbusirNecropLv();
PhePalOuter2.accept("k", MakeMe, [PhePalOuter2]);

Because I’m passing my instance to the function, which is reference…that’s not going to choke anything hopefully.

From what I can tell, things look good. Even that keybind for the “k” key is cleaned up.

The call to DirectObject.destroy() will remove key bindings. Without it, the key binding would not be removed and the object would not be deleted.

The “del PhePalOuter2” in your code above is pointless. All it does is dereference the local variable PhePalOuter2, which is about to go out of scope automatically at the end of the function anyway.

David

Thirty Minute Concept Art

Was taking a break and start “doodling.” Nothing special.

I think the bullet is gonna damage the blade.