-
Notifications
You must be signed in to change notification settings - Fork 129
Textures are never deallocated #35
Comments
Thanks for the clear repro steps. We'll take a look at this! |
@kircher1 Just got this error
I'm not sure if it's related since it's the first I've seen of it and the member names seem to be obfuscated, but I figured I'd let you know. It was thrown during some routine panning and zooming. I wasn't doing anything crazy. Maybe I just zoomed in too far, but I imagine the map renderer's min/max zoom level should prevent loading tiles at invalid zoom levels. |
Sorry to bug you about this; I'm sure it's being looked into, but I just wanted to check in to see if you've got any new info on the issue, even if it's tentative. The project I'm working on has a pretty tight deadline and we won't be able to use this sdk right now if tiles aren't being deallocated. |
No worries. Unfortunately I've been unable to reproduce the memory leak... Would you be able to zip up a simple repro project? That would be really helpful. If so, please leave the Bing Maps key field empty on the MapRenderer! Thanks. |
Just to add, specifically I see the memory getting freed up when the MapRenderer is destroyed. Old tiles should also be deallocated over the lifetime of the map but that is based on a fixed memory threshold. When that threshold is surpassed, older tiles are destroyed. That threshold is computed by taking a percentage of system memory. 7GB seems high but maybe not if your machine has many GBs of memory. |
Thanks for sharing the repro project! I went ahead and removed the links in case there were some private keys in there. A couple of observations:
If your machine isn't coping with the memory usage, and lowering the resolution or quality doesn't help enough, a hacky workaround would be to periodically re-create the MapRenderer to clear the cache. Maybe keying that off of how many textures have been created so far. I know far from ideal, but maybe enough to unblock you in the short term. Hope that helps! |
On the point of RGB vs RGBA, the TextureTileLayer ultimately uses Unity's LoadImage extension which converts JPG or PNGs to Unity textures. According to their docs, JPGs are converted to RGB texture format and PNGs are converted to RGBA. Since this is automatically determined by Unity, there isn't a way to change it, other than changing the underlying image data to JPGs. |
Gotcha, thanks for this info. I did another test with lower texture resolution and the texture memory didn't balloon nearly up as fast which is an improvement. On my machine with 16 GB it still ended up filling almost all the way since more than a third of memory was already being used by other programs. However, I saw that the used memory plateaued right below 16 GB in the task manager, but weirdly kept increasing in the Unity profiler beyond 16 GB. I'm not sure why Unity would report more used memory than my PC actually has, but I think (in addition to the large memory limit) that was what mislead me into thinking there was a leak. That being said, I've continued testing by panning until my system memory is full and then restarting. Sometimes I'd exit play mode the moment it plateaued and sometimes I'd keep panning for a minute or so to see how it handled not having any more available memory. I tried this 6 times and it crashed once when trying to exit play mode; presumably from struggling to free the 10 or so GB of memory it was using. The application definitely starts struggling to work when the memory is maxed out and it has some pretty severe hitching. Exiting play mode would also take upwards of 45 seconds. Like you said, being able to set the max memory for tiles is definitely needed. Unless there's some reason it shouldn't be changed on the fly, some inspector property on the map renderer would suffice I think. |
v0.4.2 allows for customizing the max cache size and significantly reduces the default amount of memory used by the cache. |
Describe the bug
When panning and zooming tiles are created, but old tiles are never deallocated. I've had multiple crashes due to this as my system has completely run out of memory 😬 This happens at runtime, but is even worse in the editor as it seems impossible to destroy the all the textures without restarting.
Destroying the map renderer or switching scenes doesn't even seem to free all the tile memory. It frees a bit, but in my simple project where texture memory is (practically) only allocated by the map renderer currently about 7GB of memory is allocated by textures. Creating a new scene drops the amount by a bit, but the only way to free the memory is to restart Unity. If I restart Unity only a few hundred MB in texture memory is allocated.
To Reproduce
Expected behavior
The map renderer should have a maximum amount of memory allowed to be used and tiles should be deallocated when the limit is surpassed.
Environment (please complete the following information):
Additional context
Api Compatibility Level - .NET 4.x
The text was updated successfully, but these errors were encountered: