Re: overcoming a dealocating memory problem ?
From: Michael Borgwardt (brazil_at_brazils-animeland.de)
Date: 05/12/04
- Next message: javaguy44: "EJB - Why do we need java persistence on top of a database?"
- Previous message: Anguel Stankov: "Re: Pasting a file into a Java String"
- In reply to: Jole: "overcoming a dealocating memory problem ?"
- Next in thread: Tony Morris: "Re: overcoming a dealocating memory problem ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 12 May 2004 11:18:51 +0200
Jole wrote:
> 2) obj = (MyClass) in.readObject();
>
>
> the compiler tells me that obj is constant and can't be assigned again. I
> was hoping i could do something like this at step 2:
>
> delete obj; //free memory
> obj = (MyClass) in.readObject(); //read in new version of object from file
> //and assign it to the same reference
Your problem has nothing to do with allocation of memory. The only case where the
compiler wouldn't allow you assign to the variable again is if it's declared as
"final". Remove that keyword from the variable declaration and it should work.
You seem to be completely unfamiliar with the way memory management in Java works.
It uses "garbage collection". Memory is allocated when an object is created via
"new" (or cloned, or deserialized) and deallocated automatically when there are
no more references to it.
You have a potential problem in your code because ObjectInputStream retains
references to all objects read from it, so their memory can't be reclaimed
as long as the stream is not closed or reset.
- Next message: javaguy44: "EJB - Why do we need java persistence on top of a database?"
- Previous message: Anguel Stankov: "Re: Pasting a file into a Java String"
- In reply to: Jole: "overcoming a dealocating memory problem ?"
- Next in thread: Tony Morris: "Re: overcoming a dealocating memory problem ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|