Page 1 of 1

Error: "Memory leak warning! Don't let buffer pool die without unpinning it!"

Posted: Wed Sep 11, 2019 8:31 pm
by tomweiland
I'm getting an error when shutting down my server:

Code: Select all

Memory leak warning! Don't let buffer pool die without unpinning it!
I'm using this to stop everything physics-related, but it doesn't seem to be doing the trick (got it from the SimpleSelfContainedDemo):

Code: Select all

Globals.physics.simulation.Dispose();
Globals.physics.simulation.BufferPool.Clear()
I don't get this warning when I close the console window by clicking the X in the corner, it only happens when I set the condition that keeps the thread running to false.
What am I missing? Do I need to give it some time before letting the console app die?

Re: Error: "Memory leak warning! Don't let buffer pool die without unpinning it!"

Posted: Wed Sep 11, 2019 8:37 pm
by Norbo
Could be one of the thread-specific BufferPools used by the IThreadDispatcher implementation. The IThreadDispatcher is not 'owned' by the simulation, so it has to be disposed separately.

Also, if you only ever encounter this on shutdown, you could ignore it and just let the process termination take care of it :)

Re: Error: "Memory leak warning! Don't let buffer pool die without unpinning it!"

Posted: Wed Sep 11, 2019 9:03 pm
by tomweiland
Norbo wrote: Wed Sep 11, 2019 8:37 pm Could be one of the thread-specific BufferPools used by the IThreadDispatcher implementation. The IThreadDispatcher is not 'owned' by the simulation, so it has to be disposed separately.
Is there anything I can do to prevent it? Or at least narrow down the cause?
Do I need to dispose the thread dispatcher like in the demo? Although, I haven't implemented IThreadDispatcher, so I can't access it...?
Norbo wrote: Wed Sep 11, 2019 8:37 pm Also, if you only ever encounter this on shutdown, you could ignore it and just let the process termination take care of it :)
Good to know, although it's a little annoying to have that pop up every time I shut down.

Re: Error: "Memory leak warning! Don't let buffer pool die without unpinning it!"

Posted: Wed Sep 11, 2019 10:38 pm
by Norbo
The Simulation doesn't create any BufferPools of its own- any BufferPools are directly or indirectly created outside and should be accessible. If you haven't created any IThreadDispatcher, there may be some other miscellaneous BufferPool hiding. Finding every reference to BufferPool in the project could do it. I think some part of VS's memory profiler tools could also give you an allocation graph too, can't remember exactly off the top of my head. Worst case scenario, you could add an invasive stack recording on BufferPool creation and print it in the debug finalizer that tells you where the offending instance got allocated.

Re: Error: "Memory leak warning! Don't let buffer pool die without unpinning it!"

Posted: Wed Sep 11, 2019 11:59 pm
by tomweiland
The only references to BufferPool that I created are these:

Code: Select all

public BufferPool bufferPool { get; private set; }
bufferPool = new BufferPool();
The rest of the references are all in classes (IntersectionAlgorithm and CharacterControllers) which I copied directly from the demos.

I actually managed to figure out the problem. I'm stopping the server on a thread that isn't the physics thread, so I was setting

Code: Select all

Globals.physics.simulation.Dispose();
Globals.physics.simulation.BufferPool.Clear()
to be called from the main thread, but I was falsifying the condition that keeps the server running right away, so the Dispose and Clear methods weren't actually being run. That was an oversight on my part, sorry for taking up your valuable time :(