Search Issue Tracker
By Design
Votes
1
Found in
2018.3.0a1
2018.3.12f1
2019.1.0a1
2019.2.0a1
Issue ID
1146884
Regression
No
Tilemap leaks memory when Tilemap.ResizeBounds() and/or Tilemap.ClearAllTiles() are called
Reproduction steps:
1. Open the attached Project from "TilemapTest.zip"
2. Open a Profiler Window with a Memory Profiler inside of it
3. Open and Play "SampleScene"
4. Click anywhere inside of the Game View
Expected result: Total Object Count inside of Memory Profiler does not increase for every new rendered tile
Actual result: Total Object Count inside of Memory Profiler increases for every new rendered tile
Reproduces on 2018.3.13f1, 2019.1.0f2, 2019.2.0a12
Could not reproduce on 2017.4 due to missing Tilemap methods
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Shadow cascades and lights flicker when using Shadowmap Sampling
- Frame Debugger is not disabled when switching Scenes if the Frame Debugger window is not open during the transition
- Standalone Profiler Targets another Project if a Standalone Profiler was launched in it before when switching between Edit or Play Mode Targets
- Crash on ForwardRenderLoopJob when opening a specific project
- [Android] Memory leak and eventual crash on Snapdragon 8 Gen 1+ devices when a Clear Pass is executed after Framebuffer Fetch
Resolution Note:
Regarding this issue, I noticed that in your GameManager.cs script, at lines 152 and 155, you are calling:
tilemap.SetTile(pos, Tile.Instantiate<Tile>(tilePrefabs["Dirt"]));
and
tilemap.SetTile(pos, Tile.Instantiate<Tile>(tilePrefabs["Grass"]));
When Tile.Instantiate<Tile>() is called, it creates a copy of the Tile ScriptableObject. This causes the increase in object count that you see. The thing to note is that you will need to manage the copy of the ScriptableObject yourself, which includes the destruction of that instance.
The following link gives a summary about the behaviour of the ScriptableObject.
https://forum.unity.com/threads/scriptableobject-behaviour-discussion-how-scriptable-objects-work.541212/
Instead, I would suggest using the Tile directly on the Tilemap, as internally the Tilemap Component will create and manage the instances of that Tile for you. You can do so by using this, for example:
tilemap.SetTile(pos, tilePrefabs["Grass"]);