re-use an instance

  • Thread starter Thread starter Martijn Mulder
  • Start date Start date
M

Martijn Mulder

Can I call the constructor on an object that is already in memory? The
desired behavior is that I reset the state of an object with (one of the)
constructs of its type, but not have it allocate dynamic memory and not be
subjected to the garbage collector (until the process ends).
 
Martijn said:
Can I call the constructor on an object that is already in memory?
No.

The desired behavior is that I reset the state of an object with (one of the)
constructs of its type, but not have it allocate dynamic memory and not be
subjected to the garbage collector (until the process ends).

In that case, you should implement a "Reset" method which resets the
internal state.

Jon
 
Hi,

Martijn Mulder said:
Can I call the constructor on an object that is already in memory?
No

The desired behavior is that I reset the state of an object with (one of
the) constructs of its type, but not have it allocate dynamic memory and
not be subjected to the garbage collector (until the process ends).

The way to go is to delegate the actual assignment of values to another
method, this method can be public and both the contructor and the resetter
can call it
 
No, that's why it is called *constructor* because it constructs new objects.

Just move your code in a separate public method and use it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top