Here’s an easier question to help me get started on breaking this stuff down on my own.
How do I delete an instance of a class that inherits from DistributedNode, and is created through clientrepository.createDistributedObject?
I’ve created two versions of my Shot class, which I use for all of the different kinds of projectiles in the game. One version inherets from DistributedNode and gets propogated over the network, and one version doesn’t inherit from anything and doesn’t get propogated over the network.
Both versions have the same method for cleaning up their own content, called destroy. It removes the NodePaths, the collision traverser, ends the movement task, etc.
The version that inherits from DistributedNode also has a method called delete, which calls DistributedNode.delete(), which I took from the Net example you made and you pointed me to.
When I call the destroy method on the version that inherits from nothing, the class instance gets removed from memory and the del method is called.
When I call the destroy and delete methods on the version that inherits from DistributedNode, the del method is never called.
I did some further testing with getrefcount, and I found that the DistributedNode version has one extra reference to it somewhere after delete and destroy have been called. (I printed getrefcount from inside the class’s task, and it reported 5 references. 1 for the temporary reference for the getrefcount call, 3 references for the running task, and 1 more.)
I’m not sure where this extra reference is being kept, or what I’m supposed to do to get rid of it.
PS: I know that a running task implies 3 references because of the following program, which prints out 5 for 250 frames and then prints out 2 until closed.
from sys import getrefcount
self.tmrc = TaskManagerRefCount(self)
self.tmrc = None
taskMgr.add(self.refCountTMRCTask, "Print Ref Count of TMRC from World")
def refCountTMRCTask(self, task):
def __init__(self, world):
taskMgr.add(self.printRefCountTask, "Print Ref Count Task")
self.count = 0
self.world = world
def printRefCountTask(self, task):
self.count += 1
if(self.count == 250):
w = World()