public class ProductListGetSet
{
static ArrayList<ProductListItems> productListItems;
ProductListItems items;
ProductListGetSet()
{
productListItems = new ArrayList<ProductListItems>();
}
public static int getProductListCount() {
return productListItems.size();
}
public void setProductListItems(String name, String price, String rating, String review) {
items = new ProductListItems();
items.productName = name;
items.productPrice = price;
items.productRating = rating;
items.productReview = review;
productListItems.add(items);
}
public static ArrayList<ProductListItems> getProductListItems() {
return productListItems;
}
public void setProductListItemsWithoutReview(String name, String price, String rating) {
setProductListItems(name, price, rating, "0");
}
public void setProductListItemsWithoutRating(String name, String price, String review) {
setProductListItems(name, price, "0", review);
}
public void setProductListItemsWithoutRatingReview(String name, String price ) {
setProductListItems(name, price, "0", "0");
}
public static void removeProductList()
{
productListItems.clear();
}
}
I am getting records from database and saving to this class.At a time i will save more than 500 records.
Is there any solution or alternative for this?
I am getting out of memmory error()(Bitmap size exceeds VM budget).
Please help me!!
The static variable productListItems is being constructed in the constructor of
ProductListGetSet. So if I construct an instance ofProductListGetSetand add 500 products usingsetProductListItems(), and in another point in my code, construct anotherProductListGetSet, my code’ll create anotherproductListItemsobject. So the first 500 members of the originalproductListItemsis in memory, and I am creating another copy of the variable.If you are constructing many instance of
ProductListGetSetin your code, say, in a loop, before the VM comes to your rescue, you might run out of memory.Though I feel that there is something else that is doing greater damage, which is probably not in the code that you posted here.