将null赋值给SoundPool对象以节省资源

huangapple go评论71阅读模式
英文:

Assigning null to SoundPool object to save resources

问题

给一个SoundPool对象赋值"null"是否可以为设备节省一些资源,如果声音文件已经被加载到内存中了?

英文:

Can assigning "null" to a SoundPool object save some resources for a device if a sound file has been loaded already into the memory?

答案1

得分: 0

如果您想要释放资源...调用SoundPool.release()javadoc中提到:

释放SoundPool资源。释放SoundPool对象使用的所有内存和本机资源。无法再使用SoundPool,引用应设置为null

仅仅将保存您的应用程序SoundPool引用的变量设置为null 可能会使其无法访问,资源 可能会在将来的某个时刻被垃圾回收器回收。

然而,根据我对API的理解,如果您调用release或者只是将变量赋值为null,您将无法再调用SoundPool方法来播放、暂停、恢复等之前加载的声音文件。所以这可能不是您想要做的事情。

英文:

If you want to release the resources ... call SoundPool.release(). The javadoc says:

> Release the SoundPool resources. Release all memory and native resources used by the SoundPool object. The SoundPool can no longer be used and the reference should be set to null.

Just nulling the variable that holds your app's SoundPool reference may make it unreachable, and the resources may be reclaimed by the garbage collector at some point in the future.

However, according to my reading of the API, if you either call release or just assign null to the variable, you will no longer be able to call the SoundPool methods to play, pause, resume and so on the sound files that you previously loaded. So it is probably not what you want to do.

huangapple
  • 本文由 发表于 2020年8月31日 22:38:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63672901.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定