Path: utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!xanth!mcnc!ncsuvx!shumv1!unkydave From: unkydave@shumv1.uucp (David Bank) Newsgroups: comp.lang.pascal Subject: Re: TP Dynamic variable disposal Message-ID: <4620@ncsuvx.ncsu.edu> Date: 22 Nov 89 03:20:10 GMT References: <21510@adm.BRL.MIL> Sender: news@ncsuvx.ncsu.edu Reply-To: unkydave@shumv1.ncsu.edu (David Bank) Organization: NCSU Computing Center Lines: 36 In article <21510@adm.BRL.MIL> 6600putz%ucsbuxa@hub.ucsb.edu writes: > > Does Turbo Pascal (TP compiled programs) automatically dispose of all >dynamically allocated memory created during execution of the program, or >do I, the programmer, have to manually dispose of this memory, at the >end of the program? I have a linked-list set up and of course wish to >dispose of all the memory allocated to its use at the close of my program >after saving the data file. If this is in the manual, I missed it... > > Scott Kral > UCSB My response is based on TP 3.0, as I do not (yet) have extensive experience with TP 4.0 or 5.0 (one of these days I'll break the shrinkwrap on the latter). Anyway, as I understand dynamic memory allocation on the PC, requests for memory are made to DOS. DOS returns a pointer to the allocated memory or nothing if there was a problem (like no more available memory) Inside your TP program, you can return allocated memory to the heap using the Dispose() standard function. This frees memory as far as both the program and DOS are concerned. If you program terminates and does not stay resident, all memory allocated to that process (program) is immediately returned by DOS to the free heap. Again, the program musn't stay resident. The memory is returned to the heap regardless of whether it was dynamically allocated or not. DOS doesn't care - it belonged to the terminated program, now it is free memory. Hope this helps. Unky Dave unkydave@shumv1.ncsu.edu