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
- SpeedTree does not move when using WindZone
- "Undeclared identifier 'LinearToSRGB'" error is thrown when creating a color variable with HDR color mode and assigning a Custom Render Texture target in Shader Graph
- Input System package is missing when creating a new HDRP project
- Inconsistent behaviour when interacting with different dropdown types with pointer events on parent Visual Element
- Hidden GameObjects won't re-enable when they have call "DontDestroyOnLoad" function
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"]);