Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 corporate_fun · Apr 22, 2014 at 08:48 PM · androidaudiowwwclipexternal

Unload audio from external source

I'm able to load audio from an external directory by making use of the WWW class. The problem I'm having is that I can't get the audio to unload and this is causing memory leaks.

I am loading audio like this and then storing all audio files in a dictionary for reference:

     newAudioSource = gameObject.AddComponent<AudioSource>();
     newAudioClip = new WWW("file:///" + absolutePath).GetAudioClip(false, false);
     if (newAudioClip != null)
     {    
         newAudioSource.clip = newAudioClip;
         audioDict[audioKey] = newAudioSource;
     }

and then I'm trying to unload the audio like this:

         AudioSource sourceToRemove = audioDict[key];
         audioDict.Remove(key);
         Destroy(sourceToRemove);

But that's not working because I can see the that the audio memory is not going down in the profiler. Eventually the app crashes because of too much memory.

Comment
Add comment · Show 6
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 xortrox · Apr 22, 2014 at 08:51 PM 0
Share

What happens if you set audioDict[key].clip = null; before destroying? If that doesn't work, try using System.GC.Collect() after the destroy, let me know how it goes.

avatar image supernat · Apr 22, 2014 at 08:54 PM 0
Share

Is newAudioSource and newAudioClip being stored anywhere else? Only thing I can think of is to grab sourceToRemove.clip, set the clip to null, and destroy the clip as well. $$anonymous$$aybe the AudioSource is storing the clip in a static reference array so that if any other AudioSource adds the same clip, it can use the same reference, or it could be making a single static deep copy. You might check if there is another programmatic way to remove the clip too.

avatar image corporate_fun · Apr 22, 2014 at 09:23 PM 0
Share

Thanks for the replies guys. Unfortunately, none of the suggestions have worked.

I know that there are not any other references to these objects because I am able to make some modifications to the code to load the audio using the Resources directory and using Resources.load ins$$anonymous$$d of the WWW class to load. With that modification I am able to unload the audio memory with the originally posted code.

I wish I could load the audio using the Resources class but there is a 50$$anonymous$$B limit to the size of an Android app for the play store so I need to move the audio assets into an expansion file and so I need to load them using the WWW class.

avatar image xortrox · Apr 22, 2014 at 09:58 PM 0
Share

What format are you using for the files? (mp3 would be one of the best formats to go for here)

avatar image corporate_fun · Apr 22, 2014 at 10:13 PM 0
Share

Currently, I am using wav and mp3 files, though we are looking into compressing the wav files into mp3 as long as looping them doesn't cause any audio issues.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bryarey · May 10, 2017 at 10:19 AM

Try to dosomething like: AudioClip clipToUnload = audioDict[key]; clipToUnload.UnloadAudioData(); Destroy(clipToUnload); And after that remove your dictionary`s item and/or audio source, if need.

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

24 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

Related Questions

WWW.audioClip not playing on android build 1 Answer

Unity download audio 1 Answer

Find audio in android 0 Answers

loading/streaming audioclip using www class [android] 0 Answers

Why does sound on Android play at double speed and crackle? 3 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