Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DarkDayZ · Mar 05, 2018 at 12:35 PM · 2dmemory

Unload Sprite Atlas from memory

Hello! We are loading Sprite Atlases at runtime in our game using Resources.Load(). But when trying to eliminate all references to unload the atlas and therefore all the rextures from memory, there is always one reference left according to the profiler, which is the "SpriteAtlasDatabase".

So, how do you unload a sprite atlas completely and correctly?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Khw5792 · Aug 24, 2018 at 09:11 AM 0
Share

I am also the same problem. The reference count by SpriteAtlasDatabase is protected by Resources.UnloadUnusedAssets. Is this behavior only in the editor or is it a bug?

avatar image arthuronoszko Khw5792 · Aug 24, 2018 at 09:29 AM 0
Share

I am pretty sure that it was behaving like this when building to an iPad as well. I can not say if it is a bug or not, but I will try to reproduce this with a completely new project and see if it occurs there as well. To be continued :)

avatar image hieutt_unity65 · Jul 02, 2021 at 10:21 AM 0
Share

Same issue :((

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DarkDayZ · Mar 09, 2018 at 10:18 AM

In case someone happens to have weird memory occupation caused by sprite atlases: Delete your lib files. That fixed it for us. The lib files contain a huge amount of cached atlas files (ca. 11GB in our case). Cleaning that up got rid of the weird behaviour.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by arthuronoszko · Aug 08, 2018 at 07:52 AM

Hi! I have a similar problem, where I load the new scene, where the Atlas is not referenced in any way, but according to the Profiler, it still has a lot of references to it.

This is the code for when I am changing scenes:

 IEnumerator Transition(string fromScene, string toScene) {
             yield return SceneManager.UnloadSceneAsync(fromScene);
             yield return StartCoroutine(LoadSceneAndSetActive(toScene));
             yield return Resources.UnloadUnusedAssets();
         }
 
         IEnumerator LoadSceneAndSetActive(string sceneName) {
             yield return SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
             var newlyLoadedScene = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
             SceneManager.SetActiveScene(newlyLoadedScene);
         }

Am I unloading the assets correctly? If I get rid of the SpriteAtlases, then I do not have any references to any of the sprites in the previous scene, so my conclusions is that is has to do something with SpriteAtlas.

Anyone got the same problem as I? Or am I profiling wrong? I have also tried to profile with the MemoryProfiler (https://bitbucket.org/Unity-Technologies/memoryprofiler) where when I select the atlas it says: "No root is keeping this object alive. It will be collected next UnloadUnusedAssets() or scene load"

alt text


screen-shot-2018-08-08-at-094717.png (18.1 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MartinTilo · Apr 23 at 01:53 PM 0
Share

I think the bitbucket memory Profiler didn't take Hide flags into account, like the Editor only flag: HideAndDontSave.

These might keep these around in memory in the Editor for Editor purposes. Be sure to make a Development builds and profile that. Also try out the Memory Profiler Package that shows the HideFlags in the Advanced foldout of the Selected Item Details section.

avatar image
1

Answer by JohnstableHome · Oct 17, 2018 at 05:21 AM

If you use the SpriteAtlasManager callbacks, you can load and unload the Atlases yourself, instead of going through the database.

See example in https://github.com/jconstable/SpriteSleeper

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by MartinTilo · Apr 23 at 01:58 PM

The Memory Profiler Module doesn't show you the full reference chain from your C# scripts and it gives cryptic remarks if something is kept around because of Hide flags, like the Editor only flag: HideAndDontSave.

These Flags might keep these sprite atlases around in memory in the Editor for Editor purposes (like generating, regenerating or displaying their preview). Be sure to make a Development builds and profile that. Also try out the Memory Profiler Package that shows the managed references to these Atlases. It also shows the HideFlags in the Advanced foldout of the Selected Item Details section.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

159 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

Memory game logic 1 Answer

Using -Texture Quality: Half- res and mip maps 0 Answers

Unity iOS memory usage 0 Answers

2D Animation does not start 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges