将 null 分配给 SoundPool 对象以节省资源
Assigning null to SoundPool object to save resources
如果声音文件已经加载到内存中,将“null”分配给 SoundPool 对象是否可以为设备节省一些资源?
如果要释放资源...调用SoundPool.release()
。 javadoc 表示:
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
.
只需清空保存应用程序 SoundPool
引用的变量 可能 使其无法访问,并且资源 可能 被回收由垃圾收集器在未来的某个时候。
但是,根据我对 API 的阅读,如果您调用 release
或只是将 null
分配给变量,您将无法再调用 SoundPool
播放、暂停、恢复等您之前加载的声音文件的方法。所以这可能不是你想要做的。
如果声音文件已经加载到内存中,将“null”分配给 SoundPool 对象是否可以为设备节省一些资源?
如果要释放资源...调用SoundPool.release()
。 javadoc 表示:
Release the
SoundPool
resources. Release all memory and native resources used by theSoundPool
object. TheSoundPool
can no longer be used and the reference should be set tonull
.
只需清空保存应用程序 SoundPool
引用的变量 可能 使其无法访问,并且资源 可能 被回收由垃圾收集器在未来的某个时候。
但是,根据我对 API 的阅读,如果您调用 release
或只是将 null
分配给变量,您将无法再调用 SoundPool
播放、暂停、恢复等您之前加载的声音文件的方法。所以这可能不是你想要做的。