私のj2meアプリケーションでは、ユーザーがアイテムをクリックするたびに小さなサウンドファイルを再生する必要があります。しかし、問題は、10〜14回後にサウンドファイルを複数回再生すると、メモリ不足の例外が発生することです。ファイルを再生するたびにプレーヤーを解放しますが、それでもメモリ不足の例外が発生します。コードスニペットは次のとおりです。
public void playSound(String soundFile) {
try{
if (player!=null) {
try {
player.deallocate(); //deallocate the unnecessary memory.
} catch (Exception ex) {
player=null;
System.gc();
}
}
player = Manager.createPlayer(getClass().getResourceAsStream(musicFolder + soundFile), "audio/mpeg");
// player = Manager.createPlayer(is, "audio/mpeg");
player.realize();
// get volume control for player and set volume to max
VolumeControl vc = (VolumeControl) player.getControl("VolumeControl");
if (vc != null) {
vc.setLevel(100);
}
player.prefetch();
player.start();
isException=false;
} catch (Exception e) {
isException=true;
}
}
誰かが何が悪いのか教えてもらえますか?