• 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 ChenMo2 · Jun 07, 2013 at 03:00 AM · assetbundle

When I load 200+ asset bundles, memory leak will happen.

Hello everyone! I'm having a terrible trouble now, help me please!~~

In our project, every asset like texture, material, model has been bundled as a asset bundle. When they are be building, use BuildPipeline.PushAssetDependencies() and BuildPipeline.PopAssetDependencies() so that every bundle will be very small. I call BuildPipeline.BuildAssetBundle() use BuildAssetBundleOptions.CollectDependencies argument so that dependencies will be tracked. And then I encrypt all the asset bundles.

All assets in the scene is made into a prefab named A. Before I instantiate A , I need to do these things:

1.Decide which asset bundles are using by A, get the sets.

2.Read bytes from file, and X byte buffers to contain dencrpyted bytes. X is equal to the number of the asset bundles.

3.Call AssetBundle.CreateFromMemory to build asset bundle for every byte buffer.

4.Call AssetBundle.Unload(false) to free memory for every asset bundles. Get A's reference at the same time. Object instance = assetbundlePool[A].assetBundle.mainAsset ;

I do this time and again, memory leak will happen, but not every time.Leak a huge memory oh my god!

5.Instantiate instance, then the all the assets will be present.

6.When I want to destory all the assets, I call GameObject.Destory(instance). Because all the assets is made into one game object, so if I destory it will give up all the referencies, so the assets' memory will be freed when garbage collection happens I think.

That's all, I don't know how unity achieve asset bundle.I hate this feeling.

Welcome to follow up! Thanks ahead! Merry Christmas! Ha ha, a cold joke...

Comment
Add comment · Show 2
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 ChenMo2 · Jun 07, 2013 at 04:09 AM 0
Share

I'v done all I can do I think, but I can't control the memory leak. I'm a user, not a programmer I think, this make me sad.

avatar image ChenMo2 · Jun 09, 2013 at 03:56 AM 0
Share

I'd givven up~

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by RalphTrickey · Jun 09, 2013 at 04:21 AM

Memory leaks in C# aren't true leaks, they are seen as being in use and not collected. This is usually caused by objects being assigned to a variable somewhere, possibly in a member variable, or somewhere else. If you've got an array or GameObjects or or a List somewhere that's holding them, or something else like that, it can cause memory to grow. Event handlers can cause the same issue. Make sure to null out any objects and disconnect any event handlers that aren't used. That's the best suggestion I can give. I also found this link. http://wiki.unity3d.com/index.php?title=DetectLeaks

BTW, how do you know you have a memory leak? Managed languages like Unity are notorious for allocating all available memory and not freeing it until they need to. There are some options to for a garbage collection, etc. for normal .Net, I'm not sure about Mono. I wouldn't recommend calling them though except under very unusual circumstances by an expert.

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
0

Answer by ChenMo2 · Jun 13, 2013 at 02:20 AM

Thank you very much!

I use task manager of windows to detect memory variousness. When the program I built was running, it loaded and unloaded asset bundles repeatedly. Along with it was running, the memory it used growed. I'm sure I've nulled out all the asset bundles' reference.

Now, I've decreased the amount of asset bundles, and memory leak won't happen. I've test it use task manager. I don't know how AssetBundle works, it's really a trouble when too many asset bundles are used.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

How to import the object from server to unity 2 Answers

How to auto find a component inside an assembly (dll)? 0 Answers

Load scene with navmesh from asset bundle 1 Answer

apply texture on OBJ files automatically in batchmode 1 Answer

Unauthorized use of Caching API in webplayer 0 Answers


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