I have more than 20 category in which each category contains more than 400+ subcategories in webapplication.
When I press perticular category button it throws java.lang.OutOfMemoryError
. Here is java file code. In this code, I am putting subcategory data in to json object and then add it to json array.
String responceObjectStr;
JSONObject responseObject;
for(int i=0;i<category.length;i++){
responseObject = new JSONObject();
JSONArray ja = new JSONArray();
responseObject.put(category[i],Categorywisedata);//adding data to response
ja.put(responseObject);//putting response object to JSONArray
responceObjectStr = new String(ja.toString().getBytes("UTF-8"));
out.print(responceObjectStr);//response
responceObjectStr = null;
responseObject = null;
}
Here in each category it may have 400+ subcategory.
When I press the category button it shows java.lang.OutOfMemoryError
.
How to solve this. I don't want to increase JVM memory for this. I want Java code solution to handle this.