英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论