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
- Game View Tab Scale changes erratically when a Unity Tab is on a different screen with a differing Display Scale
- Six way lighting receiving wrong lighting from APV when set to World Space
- Crash on SortByExecutionOrder when interrupting the .androidpack import process
- ShaderGraph tab header changes the icon to the VFX Graph icon when ShaderGraph and VFX Graph with the same name are both opened
- The Build Profiles window has usability issues when the panel takes up less than 30% of the screen width
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"]);