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
- Reflection problems when unbaked Reflection Probes are present
- Light Explorer columns sorting arrow is too small
- Context menu actions (Collapse All, Expand All, Enable All, Disable All, Remove All, Reset All) do nothing in Volume component
- [Android] Audio volume decreases when returning to the app during screen recording
- Graphical issues are caused by GPU Occlusion Culling when using Amplify Shaders
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"]);