当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Spinner - setAdapter causes memory leak

问题描述:

I have the below code, which sets up a simple spinner, however whenever I fire the setAdapter, my app crashes out due to a memory leak (memory heap just keeps growing until it hits OutOfMemoryException).

final ArrayList<String> items = new ArrayList<String>();

AssetManager assetManager = getApplicationContext().getAssets();

try {

for (String file : assetManager.list("")) {

if (file.endsWith(".plist")) items.add(file.replaceAll(".plist$", ""));

}

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

ArrayAdapter<String> adp = new ArrayAdapter<String>(this,

android.R.layout.simple_spinner_item, items);

countrys.setAdapter(adp);

countrys.setOnItemSelectedListener(new OnItemSelectedListener() {

public void onItemSelected(AdapterView<?> arg0, View arg1,

int arg2, long arg3) {

int index = arg0.getSelectedItemPosition();

readPlistContents(items.get(index) + ".plist");

}

@Override

public void onNothingSelected(AdapterView<?> arg0) {

// TODO Auto-generated method stub

}

});

From the code, I can't see why this might be happening.

分享给朋友:
您可能感兴趣的文章:
随机阅读: