overcoming a dealocating memory problem ?

From: Jole (no_spam_at_nospam.com)
Date: 05/12/04


Date: Wed, 12 May 2004 08:48:21 GMT

Hi
I'm using serialization to read in an object from a file. My code basically
does this:

1)MyClass obj = (MyClass) in.readObject();

('in' is an ObjectInputStream wrapped around a FileInputStream object, ie
the code reads an object stored in a file on disk)

Now, what happens is my code does this once at the start (works fine), but
later i need to do the same thing, to read in an updated version of the
object. ie, i need to do this again:

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

(don't pay attention to the syntax, but the concepts..ie the above frees the
associated memory and then reads in a new copy from the file and assigns it
to the reference obj)

There doesn't seem to be a way to do it. Any ideas?

thanks
Jole



Relevant Pages

  • passing an instance of a class as a parameter in interops...
    ... public interface _myclass ... public interface _myclasslist ... void Add(_myclass obj) ... In my asp page I try the following: ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Method chaining
    ... temp1 = MyClass() ... obj = getattr ... where the intention probably would be to generate a list of lists (or other ... Localizing the use of ...
    (comp.lang.python)
  • overcoming a dealocating memory problem ?
    ... 1)MyClass obj = in.readObject; ... associated memory and then reads in a new copy from the file and assigns it ... to the reference obj) ...
    (comp.lang.java)
  • Re: IDE for PHP
    ... Gary L. Burnore wrote: ... MyClass $obj = new MyClass; ... Since PHP is loosely typed, the "MyClass" preceding $obj is bad syntax. ...
    (comp.lang.php)
  • Re: Why sometimes a statement after Thread.Start() is not executed?
    ... manipulate _obj from within your thread, it needs to be passed in thru the ... >> Sub Start ... >> _obj = new MyClass ... > If the constructor is just a default constructor, ...
    (microsoft.public.dotnet.framework)