PDA

View Full Version : "New" operator



vratojr
21st April 2006, 15:42
Hi all, today a question arised inside my mind:

If I have a cycle like this:


Classe *a;
while( ... ){
a = new Classe();
}


What happens?
Will I continue on allocating new instances of Classe on the heap or the same part of memory is used at each allocation?
Briefly,I mean for example, if I use an infinite cycle, will I run out of memory or not?

The correct way would be


Classe *a;
while( ... ){
a = new Classe();
delete a;
a = 0;//Optional
}

true?

Thanks,

Simone

Michiel
21st April 2006, 15:44
You will fill up the memory and eventually you will run out. It's like you said. You have to explicitly delete it to free the memory.