This question has nothing to do with the Adapter
“capacity”. Instead, it is related to the amount of memory allocated by your app.
It has a reserved heap in order to allocate objects, if you pass this limit you will get an Out of Memory Exception
Here a little test, it could give you an idea about the amount of data that you could allocate. But be aware that in this example the object contains just an String
, if it were a gorgeous Bitmap
the amount of objects to allocate would be much much much less.
//MemoryActivity
public class MemoryActivity extends Activity {
private List<TestObject> _testObjects = new ArrayList<TestObject>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_memory);
coolGuysDoNotLookBackAtExplosion();
starCountdown();
}
private void starCountdown() {
new CountDownTimer(300000, 500) {
public void onTick(long millisUntilFinished) {
TextView tv_watcher = (TextView) findViewById(R.id.tv_watcher);
tv_watcher.setText(getMemoryUsage());
}
public void onFinish() {
starCountdown();
}
}.start();
}
private String getMemoryUsage() {
String heapSize = String.format("%.3f", (float) (Runtime.getRuntime().totalMemory() / 1024.00 / 1024.00));
String freeMemory = String.format("%.3f", (float) (Runtime.getRuntime().freeMemory() / 1024.00 / 1024.00));
String allocatedMemory = String
.format("%.3f", (float) ((Runtime.getRuntime()
.totalMemory() - Runtime.getRuntime()
.freeMemory()) / 1024.00 / 1024.00));
String heapSizeLimit = String.format("%.3f", (float) (Runtime.getRuntime().maxMemory() / 1024.00 / 1024.00));
String nObjects = "Objects Allocated: " + _testObjects.size();
return "Current Heap Size: " + heapSize
+ "\n Free memory: "
+ freeMemory
+ "\n Allocated Memory: "
+ allocatedMemory
+ "\n Heap Size Limit: "
+ heapSizeLimit
+ "\n" + nObjects;
}
private void coolGuysDoNotLookBackAtExplosion(){
new Thread(new Runnable() {
@Override
public void run() {
_testObjects = new ArrayList<TestObject>();
while (true) {
_testObjects.add(new TestObject());
}
}
}).start();
}
}
//TestObject
public class TestObject {
private String sampleText = "Lorem Ipsum is simply dummy text of the printing and typesetting industry";
}
ListView
itself, you should make use of the recycling mechanism: https://mcmap.net/q/151323/-how-listview-39-s-recycling-mechanism-works. – BehnListView
with aCursor
(using aCursorAdapter
). More specifically, the benefit is that aSQLiteCursor
extends fromAbstractWindowedCursor
, which takes advantage of exposing data through aCursorWindow
(basically a buffer). As such, you should not have to worry too much about storing a gazillion items in memory, and appropriate management for all those different Android devices out there. That being said, do you really want to display a list with over a million items to the user? – SenegaLoader
would be the way to go to query the DB and retrieve aCursor
. I just didn't mention it because the loading mechanism isn't really what this question is about; it's more about "where to put the data with respect to the memory footprint. Nevertheless, a good addition. – Senega