From: "Campbell, Rolf [SKY:1U32:EXCH]" Newsgroups: comp.os.msdos.djgpp Subject: Re: About memory allocation Date: Mon, 23 Aug 1999 15:47:41 -0400 Organization: Nortel Networks Lines: 33 Message-ID: <37C1A55C.54ED7A41@NortelNetworks.com> References: <7proji$6vo$1 AT taliesin DOT netcom DOT net DOT uk> NNTP-Posting-Host: bmerhc00.ca.nortel.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.7 [en] (X11; I; HP-UX B.10.20 9000/712) X-Accept-Language: en To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com 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