Closed unitycoder closed 8 years ago
Can you post screenshot of profiler / memory sample window? (does it happen in editor only?)
Don't know why you want screenshots, the only reason I can think of is that you don't trust me, but here they are:
The focus point is the text at the top all the way to the right it says (x MB) that's the memory dump.
Before:
After:
Profiler:
Oh yeah by the way forgot to include the memory part of the profiler.
I can also confirm that the increase has something to do with the MobilePaint script.
I figured it out. Whenever you create a new byte array the memory heap goes up. But how to deallocate that memory again, hmm...
The GC should take care of the byte arrays when the scene is destroyed and the value of the byte arrays are null, but I guess for some reason they linger on between scenes, maybe there's a reference to them in an object that isn't deleted in between?
Discovered how to fix this some time ago. I bet it could be done more effectively (iterate over all public and private byte[] variables), but this works for me. Just assign the byte arrays to null and you're good to go. You don't have to explicitly call the GC, but I did it anyways to make it more instant. Place it in MobilePaint script and when the object is deleted, it's cleaned too.
I'm only using these two byte arrays. BTW if you find out how to do this more effectively like I described, could you send me the code? Thanks.
void OnDestroy() { undoPixels = null; pixels = null; System.GC.Collect(); Debug.Log(System.GC.GetTotalMemory(false)); }
nice, that solution seems fine, no other ideas right now.
unity gc> http://docs.unity3d.com/Manual/UnderstandingAutomaticMemoryManagement.html
added OnDestroy() cleaning up to v1.96