1
My appカメラプレビューレコードアプリ。 録画カメラのプレビュー中にArrayList
を使用します。グローバル変数WeakReferenceを使用すると、androidのシンボルメッセージを解決できません
private ArrayList<OutputInputPair> pairs = new ArrayList<OutputInput>();
とI記録停止ボタンのクリックで宣言
ArrayList
、私はクリックレコード停止ボタンなしで録画を続行した場合、そのstop()
方法
@Override
public void stop() {
pairs.clear();
pairs = null;
stopped = true;
}
を実行します。 が多量のメモリリークを起こします。そう
、私はWeakReference
を使用したい私はWeakReference
を使用し、メモリリックを避けるために、どのように考えて、この
//private ArrayList<OutputInputPair> pairs = new ArrayList<OutputInputPair();
private ArrayList<WeakReference<OutputInputPair>> pairs = new ArrayList<WeakReference<OutputInputPair>>(); //global variable
@Override
public void add(OutputInputPair pair) {
//pairs.add(pair);
pairs.add(new WeakReference<OutputInputPair>(pair));
}
@Override
public void stop() {
pairs.clear();
pairs = null;
stopped = true;
}
@Override
public void process() { //record method
//for (OutputInputPair pair : pairs) {
for (WeakReference<OutputInputPair> pair = pairs) {
pair.output.fillCommandQueues(); //output is cannot resolve symbol message
pair.input.fillCommandQueues(); //input is cannot resolve symbol message
}
while (!stopped) { //when user click stop button, stopped = true.
//for (OutputInputPair pair : pairs) {
for (WeakReference<OutputInputPair> pair : pairs) {
recording(pair); //start recording
}
}
}
public interface IOutputRaw { //IInputRaw class same code.
void fillCommandQueues();
}
を試す右ですか?
修正方法は、シンボルメッセージのweakreferenceの使用を解決できませんか?
ありがとうございました。
public class OutputInputPair {
public IOutputRaw output;
public IInputRaw input;
public OutputInputPair(IOutputRaw output, IInputRaw input) {
this.output = output;
this.input = input;
}
}
'それが必要とされて使用する前に確認してくださいNULL'。 – Oleg
@Olegありがとう、編集中。 –
いいえ、ペアではなく、弱く参照されたオブジェクトがクリアされた場合、 'pair.get()'はnullを返します。 – Oleg