Memory not released

In my application a bam database file is loaded and after the simulation is stopped, all memory is released, after which a new database bam file is loaded. These databases can be quite big and are divided into tiles which are flattened to optimize performance. However, each time the same database is loaded after it has been released GPU memory (measured with GPU-Z) on my RTX2080 GPU increases with around 800 MB, and memory measured with

*def getMBUsed( self ):*
  •    pid = os.getpid()*
    
  •    ps = psutil.Process(pid)*
    
  •    memUse = ps.memory_info()*
    
  •    return (memUse.vms/1048576)*
    

also increases substantially. So memory is not released.
I do tthe following to release memory at the end of each simulation:

  • find all nodepaths that are stored in lists and tables and then do obj.removeNode()
  • clear all lists with list.clear()
  • do ModelPool.releaseAllModels()
  • do TexturePool.releaseAllTextures()
  • do TexturePool.garbageCollect()
  • do for i in range(2): n = gc.collect()
    and then the system sais that the number of unreachable objects is 0

I also checked len(gc.get_referrers(nodepath)) for all nodepaths that were created and this always returns 1 which means that the garbage collection can clear the memory.

Does anyone have a suggestion how I can free all reserved memory?

I suspect the un-freed memory is in some caches. Unfortunately, I do not remember what these all are or how to explicitly clear them. You can try adding the following PRC variables to disable some caches to see if it helps, but ideally you’d be clearing instead of disabling:

state-cache false
transform-cache false
geom-cache-size 0

Where does PStats show the unfreed memory is located?

According to PStats graphics memory (context1) grows with each time the same database is loaded after it has been unloaded. Also after freeing all lists etc, graphics memory is reduced but each time to a higher level than before. I could not see any increases in system memory, so all system memory is freed.

Thank you, I tried it but it does not help. GPU memory is still increasing same as before.