I'm running a J2ME Application and run into some serious memory problems.
So I built in another step to clear the huge input string and process its data and clear it.
But it didn't solve the problem until I set input = null
and not input = ""
.
Shouldn't it be the same in terms of memory management? Can somebody explain me the difference please?
Thanks,
rAyt
for(int x = 0; x <= ChunksPartCount; x++)
{
_model.setLoading_bar_progress((x * ChunkSize));
input += web_service.FullCompanyListChunksGet(x, ChunkSize);
if((x * ChunkSize) > 5000)
{
ReadXML(input);
input = null;
}
}
Edit:
I still want to flag an answer as the solution. I think mmyers remarks are going in the right direction.
Null is a reserved keyword in the Java programming language. It's technically an object literal similar to True or False. Null is case sensitive, like any other keyword in Java. When programming in Java, it's important to write null in lowercase.
If you want to use a BufferedReader you can do the following. BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; while ((line = br. readLine()) != null) { //Do what you want with the line. }
In Java, a null value can be assigned to an object reference of any type to indicate that it points to nothing. The compiler assigns null to any uninitialized static and instance members of reference type. In the absence of a constructor, the getArticles() and getName() methods will return a null reference.
The Java programming language distinguishes between null and empty strings. An empty string is a string instance of zero length, whereas a null string has no value at all. An empty string is represented as "" . It is a character sequence of zero characters.
Every variable is actually a pointer to "Data" in memory.
input = "" assigns input to a string object. It has a length (0) and an empty array, as well as a few other pieces of data associated with it.
input.length() will return 0 at this point.
input = null makes input point to "Invalid". Null is kind of a special case that means this pointer points to NOTHING, it's unassigned.
input.length() will now throw an exception because you are calling .length on nothing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With