So if a managed allocation in the memory map appears empty, i.e. the use of Reflection or Generics and contain Type Meta data and the like. The memory Profiler currently doesn't have any information about Mono/IL2CPP internal allocations that are not scripting objects. You can see these as managed heap allocations in the memory map. It's usually just quite rare for that to happen as random allocations are likely to land in these and stick around.īasically, the heap consist of chunks. Managed Heap Memory can be returned to the OS if the entire heap section has been emptied. The issue is more likely one of discovery or that the arrays have indeed been collected but have expanded of fragmented the heap already.Īlso I was slightly mistaken. dlls like c++ Malloc/Free and such wouldn't be captured. You could take a look at the Memory Map (Diff) in the memory profiler packages, to get a better understanding of all the memory changes, including allocations without Objects and reserved memory sections.Ĭlick to expand.No that should still show up, only native allocations made in. That is, if this really is just down to temporary memory use and not a genuine memory leak and/or heap fragmentation. You can only try to avoid the memory to expand to this degree. You have no way to give that memory back to the OS, save for restarting the editor. Unity never reduces these pools and heaps though, assuming they will be used again, and getting them from the OS in the first place is performance intensive, so it just keeps the space, even if it is no longer used. If the existing native memory pools and the empty managed heap space doesn't have enough space for them, it will expand. during the loading and conversion of your textures, you allocate a bunch of memory that all needs to sit on the managed heap, potentially with native memory behind. Speaking of reserved memory: that might be where your memory usage is growing. The list you looked at in the Memory Profiler package only contains Objects, but some memory is allocated or reserved without any objects attached to it. ![]() Has anyone run into these issues before? Is there a way to force the garbage collector to collect these arrays?Ĭlick to expand.Are these used in Lambdas/ anonymous functions? Or are they just declared in the methods and once the method is done, nothing retains any references to them? For instance, I am using Texture2D.GetPixels32 and Texture2D.EncodeToPNG, both of which allocate new arrays. I have tried to reduce new allocations by reusing arrays, however there are some spots where this is just not possible. Even if I run the tool and then try to force the garbage collector to run via a separate command, well beyond the frame that the tool was run in, the memory is not freed. I don't know if this is some weird gotcha because the tool is effectively run in a single editor frame, or if the garbage collector is just not able to run in the editor. These arrays are enclosed in local methods so their memory should be theoretically freed once the local method is done executing and the garbage collector runs.įor whatever reason, they are not freed however. I allocate what I thought to be temporary arrays in different places of the tool. It looks like I have figured out what is going on. This seems likely as I have tested destroying the prefab assets themselves after they are created, and when I try to save the active scene where the terrain game objects were created/destroyed, I get this error: It seems to me that although I am destroying the terrain game objects, somehow the scene is still referencing them. However, memory continues to increase and if enough tiles are imported, the editor will crash. I use GameObject.DestroyImmediate to destroy the terrains once they are converted to a prefab asset, and try to force memory freeing by calling EditorUtility.UnloadUnusedAssetsImmediate and GC.Collect. Unity obviously has memory limitations, which I thought I got around by adding the ability to convert the generated terrains to prefabs, and then removing the terrains used to generate those prefabs from the scene. Part of the tool is importing tile sets, which could be of extremely large sizes. ![]() I have an editor tool which is importing external heightmap files and creating terrains from them.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |