- Home /
To destroy or not to destroy?
Hi!
Writing an iPad musical app, and trying to be careful with memory. I'm not sure I understand well memory management. Here is my case : I create an AudioClip using AudioClip.Create, referenced in myClip. Now, I want to change the length of that clip : var myClip : AudioClip; function Start() { myClip = AudioClip.Create(paramsHere); myClip.SetData(data,0); } function ChangeClip() { myClip = AudioClip.Create(otherParamsHere); myClip.SetData(otherData,0); }
Am I loosing the reference to the previous clip, risking a memory leak? Should I destroy first? Or is the memory alloc handled automaticaly?
Many thanks!
Answer by zzb · Jun 19, 2012 at 10:40 AM
I think you should destroy it first just like create a material
Better to destroy it just for control. I don't know much about memory for AudioClip, but it might also be a good idea to call the garbage collector.
Wow, an ancient question surfaces! Indeed, destroying is necessary. See this excellent thread on the subject.
Your answer
![](https://koobas.hobune.stream/wayback/20220613064020im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
scriptableObject as database "a question about memory" 1 Answer
Do any variables declared within methods generate memory allocation? 1 Answer
AudioClip.preloadAudioData not working 0 Answers
"stream from disc" WAV/AIFF file allocates tons of memory 0 Answers
Create AudioSource from wave in memory 0 Answers