Oh look, a memory leak!
Posted: Wed Dec 21, 2016 1:41 pm
So, I found a memory leak!
If you create one entity shape, and use it for many collidables... when those collidables go away... they don't go away, nor do data connected to them!
Because they leave an Action<CollisionShape> in the shape's event "ShapeChanged"!
This causes roughly ten gerjillion Action<CollisionShape> instances to exist, which contain a fair bit of data each...
As it is, I actually am doing exactly that... many many many many times per second!
I accidentally caused this to happen even more rapidly than normal, and looked at task manager... and bam, many gigs higher than it has any reason to be!
I managed to, eh, "fix"?, it...
Basically, I tried weakly to make it automatically clear via a finalizer because why not I don't know the BEPU code well enough to properly implement a disposable and also I was kinda hoping a finalizer would work except upon looking back, I realized it's data that references itself and as such it would never be finalized so rip that plan.
What did work, though, was adding a method to clear the ShapeChanged data, since I literally have zero use for that event as my shapes in question never change...
So I just call that every time I create a new instance of a colldidable and call it 'good enough'.
Here's relevant code if you care to see what I did bepu-side: https://github.com/mcmonkey4eva/bepuphy ... ac8e023d0f
CollisionShape -> ClearShapeChanged is the one that actually ... does anything
I'm hoping for a proper fix, which may potentially mean rewriting a fair bit of code to properly Dispose the collidables and entities that add ShapeChanged... I don't even know tbh.
If you create one entity shape, and use it for many collidables... when those collidables go away... they don't go away, nor do data connected to them!
Because they leave an Action<CollisionShape> in the shape's event "ShapeChanged"!
This causes roughly ten gerjillion Action<CollisionShape> instances to exist, which contain a fair bit of data each...
As it is, I actually am doing exactly that... many many many many times per second!
I accidentally caused this to happen even more rapidly than normal, and looked at task manager... and bam, many gigs higher than it has any reason to be!
I managed to, eh, "fix"?, it...
Basically, I tried weakly to make it automatically clear via a finalizer because why not I don't know the BEPU code well enough to properly implement a disposable and also I was kinda hoping a finalizer would work except upon looking back, I realized it's data that references itself and as such it would never be finalized so rip that plan.
What did work, though, was adding a method to clear the ShapeChanged data, since I literally have zero use for that event as my shapes in question never change...
So I just call that every time I create a new instance of a colldidable and call it 'good enough'.
Here's relevant code if you care to see what I did bepu-side: https://github.com/mcmonkey4eva/bepuphy ... ac8e023d0f
CollisionShape -> ClearShapeChanged is the one that actually ... does anything
I'm hoping for a proper fix, which may potentially mean rewriting a fair bit of code to properly Dispose the collidables and entities that add ShapeChanged... I don't even know tbh.