prime31 / Nez

Nez is a free 2D focused framework that works with MonoGame and FNA
MIT License
1.78k stars 362 forks source link

RenderObjectGroup: Object allocation of IEnumator caused memory leak #795

Closed stallratte closed 6 months ago

stallratte commented 6 months ago

Hello,

I added an ObjectLayer to a map in Tiled. The allocated heap memory increased steadily increased after adding the ObjectLayer to the layers to render. The object allocation of IEnumerator (foreach-loop) in TiledRendering#RenderObjectGroup causes this issue.

Here's a screenshot of the profiled memory which shows the memory growth after a few minutes: memory_alloc_render_object_group

With this fix the heap memory is stable.

Best regards, stallratte

stallratte commented 6 months ago

Hello,

I had to add another fix to the pull request. I'm not activly searching for issues but I sadly found another one:

I tested scene changes. I added this to the Update-method of the Game class: Scene = new BasicScene();

Heap generation2 rapidly filled up: heap_gen_2_on_orientation_changed

The cause can be seen here: on_orientation_changed_action

On scene change the current scene can't be properly removed from the heap. The event handler "OnOrientationChanged" is added on Start() but isn't removed on End().

I added a fix. Heap generation 2 is stable now: fixed_heap_gen_2_on_orientation_changed

Best regards, stallratte

prime31 commented 6 months ago

Looks good, keep em coming!