petrikvladimir / pyphysx

Python Wrapper for Nvidia PhysX simulator.
GNU General Public License v3.0
104 stars 21 forks source link

added destructors with release call to physX objects #68

Closed sebastiankupp closed 1 year ago

sebastiankupp commented 2 years ago

I observed increasing ram usage when creating and destroying scenes within a loop in python. Checking the code I could not find any release calls for the cpp PhysX objects that were created within the respective classes. Afterwards the Memory usage for my loop-test looked alright.

Please check if these changes make any sense and work in the context of having multiple python references to the same PyPhysx objects.

petrikvladimir commented 2 years ago

Hello, can you share with me your memory loop-test? I am not sure it is safe to merge this PR, it is not clear who claims the ownership between python/c++ and who should release the objects added to the scene.

sebastiankupp commented 2 years ago

Hi, here is the minimal test code that successively increases RAM usage

import pyphysx

while True:
    scene = pyphysx.Scene()
    print('eating RAM...')
    del scene

Currently objects are never deleted until the Physics singleton is destroyed at the end of the program. This is a big problem and there has to be some mechanism for releasing PyPhysX objects. As far as I know c++ PhysX objects have an internal reference counter so that objects get released when no one holds a reference to it. Thus calling release in the destructor (and decresing the ref counter) of the Python classes seems to be valid to me.

petrikvladimir commented 2 years ago

I did some testing and after I checkout your branch, it broke 01_free_fall.py example with the error Process finished with exit code 139 (interrupted by signal 11: SIGSEGV). Did you observe the same issue?

sebastiankupp commented 2 years ago

Hey, I tried to replicate your error and ran 01_free_fall.py with the destructors included. Unfortunately I could not replicate the same error message. The code runs without issues.