Load JSONModel out of memory
Thank you for attention! Please help me, anytime i try to load() any model it gives me "Throwing OutOfMemoryError "Failed to allocate a 174 byte allocation with 136 free bytes and 136B until OOM" (recursive case)". And nope, im not calling it in recursive function... It just enters the load() and never goes out. ex: JSONModel json = new JSONModel(FinalProductAudit.class); Object[] o = {"1"}; //and i make sure this key exists in FinalProductAudit! json.load(o);
any ideia what is going on? Thank you!
@OptimistNot good find. its calling itself recursively. Good find.
Any ideia how long will it take you to fix it? Really need it to work fast. Thanks!
@OptimistNot I apologize. I would subclass JsonModel for now (not ideal but works) and put in this patch:
/**
* Loads a model from the DB into the json stored in this class. It also will recreate the JSON stored in this object
*
* @param primaryKeys The keys to reference (in order of the {@link ModelAdapter#getPrimaryModelWhere(Model)})
*/
public void load(Object... primaryKeys) {
setData(new JSONObject());
Cursor cursor = new Select().from(mModelAdapter.getModelClass())
.where(FlowManager.getPrimaryWhereQuery(getTable()).replaceEmptyParams(primaryKeys)).query();
mContainerAdapter.loadFromCursor(cursor, this);
cursor.close();
}
also you'll need to place the class in the same package as JSONModel
oh yeah and don't forget to close cursor
Thnak you a lot! Just one more question :) i really don't know what to do now with mContainerAdapter how do i get it? and how i get mModelAdapter?
ok, i suppose its something like this: public JsonModel(Class table) { super(table); mModelAdapter = FlowManager.getModelAdapter(table); mContainerAdapter = FlowManager.getContainerAdapter(table); } wrong?
hey! still same scenario, im sending one key and getting this one: "W/System.err﹕ android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1"
Log.d("CURSOR_____", cursor.getCount() + " " + cursor.getColumnNames().length + " " + cursor.getColumnIndex("final_product_audit_id")); gives me: D/CURSOR_____﹕ 1 21 0 so i make sure its not empty and i have all columns name.
on execute mContainerAdapter.loadFromCursor(cursor, this); catching in these lines: if (cursor.isNull(indexfinal_product_audit_id)) { modelContainer.put("final_product_audit_id",null); } else { modelContainer.put("final_product_audit_id",cursor.getLong(indexfinal_product_audit_id)); }
found it! on isNull() it throws exception cz of not being at any position. so just before calling mContainerAdapter.loadFromCursor(cursor, this); added cursor.moveToFirst(); finally it loads data! Thank you very much! works perfectly!
You're welcome. We will keep this open until fixed in 1.8.1