Mail Archives: djgpp/1999/08/23/18:45:04
Michael Stewart wrote:
> OmniMeta wrote in message ...
> >My question is :
> >if i do this :
> >
> >int *p;
> >int main()
> >{
> > p = new int;
> > return 0;
> >}
> >
> >Here I didn't use the delete operator to free p
> >Did p will be automaticaly deleted with the end of the program, or did p
> >will stay in memory until i reboot ?
>
> p will be free'd by the OS. Although it is good practice to free up all
> dynamic memory yourself just in case the OS doesn't do it properly.
It's not the OS that free's the pointer, it is DJGPP. The 'free' function
doesn't really return the memory to the OS anyways, it just marks it as
usable for malloc. So when your program ends, all memory that was allocated
will be returned to the OS regardless of what your program does. But, this
is not 'portable'. Some other compilers do very bad things when you don't
free all of the memory you allocated (Borland C++ 3.1 code will crash your
entire machine in real DOS).
--
-Rolf Campbell (39)3-6318
- Raw text -