The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Ratch on February 25, 2006, 01:05:04 AM

Title: Memory Loss
Post by: Ratch on February 25, 2006, 01:05:04 AM
To the Ineffable All,

     I was wondering if someone can settle once and for all whether or not failing to do a LocalFree for every LocalAlloc results in memory that is unusable until a fresh reboot.  In other words, after a program that uses LocalAlloc finishes its execution, is the O/S smart enough to release any memory assigned to the program?  Please do not answer this question if you do not know for sure.  Or if you do answer this post and don't know for sure, say you do not know for sure.  And what about file handles and device contexts?  Thanks, Ratch 
Title: Re: Memory Loss
Post by: hutch-- on February 25, 2006, 01:29:54 AM
Ratch,

It has been the case in win32 differing from win16 that when the program exits, the OS recovers any allocated memory. Where you can get into trouble with a memory leak is while the app is still running as it may exceed what is available over a long period or if it is being leaked at high speed in a loop.
Title: Re: Memory Loss
Post by: donkey on February 25, 2006, 02:33:16 AM
Absolutely, the memory is freed. There is no distinction between LOCAL and GLOBAL heaps in Win32 and part of LdrShutdownProcess is  a heap walk using RtlWalkHeap that systematically frees all objects, memory and other that are created by the process as well as invalidating any handles used. Actually during the call to RtlValidateprocessHeaps which is part of the ExitProcess function, the OS will obtain information on each heap allocated to a process and call NtlFreeVirtualMemory for each one. So yes, all the memory is freed.
Title: Re: Memory Loss
Post by: Ratch on February 25, 2006, 03:50:56 AM
hutch-- and donkey,

     Thank you both for your definitive answers. And also any others of the Ineffable All who might participate in this thread later.  Ratch
Title: Re: Memory Loss
Post by: hutch-- on February 25, 2006, 04:53:07 AM
Ratch,

When I first saw the topic, I thought there was someone else with advanced senile decay.  :bg
Title: Re: Memory Loss
Post by: PBrennick on February 25, 2006, 10:42:19 PM
Personally, I would consider it an honor to be a member of that club.
Paul
Title: Re: Memory Loss
Post by: Tedd on February 27, 2006, 11:38:21 AM
I used to be a member of that club..... I think... err.... wait.... what were we talking about again?
Title: Re: Memory Loss
Post by: Mincho Georgiev on February 27, 2006, 11:59:57 AM
My membership starts this morning when i wake up with my head, too heavy for my shoulders after last night's vodkin' holiday  :bg
Title: Re: Memory Loss
Post by: Mark Jones on February 27, 2006, 05:22:19 PM
"50 watts per channel, baby-cakes!"  :toothy
Title: Re: Memory Loss
Post by: Mincho Georgiev on February 27, 2006, 06:09:21 PM
And definitely with surround effect, Mark  ::)