News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Memory Loss

Started by Ratch, February 25, 2006, 01:05:04 AM

Previous topic - Next topic

Ratch

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 

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

donkey

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.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Ratch

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

hutch--

Ratch,

When I first saw the topic, I thought there was someone else with advanced senile decay.  :bg
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

PBrennick

Personally, I would consider it an honor to be a member of that club.
Paul
The GeneSys Project is available from:
The Repository or My crappy website

Tedd

I used to be a member of that club..... I think... err.... wait.... what were we talking about again?
No snowflake in an avalanche feels responsible.

Mincho Georgiev

My membership starts this morning when i wake up with my head, too heavy for my shoulders after last night's vodkin' holiday  :bg

Mark Jones

"50 watts per channel, baby-cakes!"  :toothy
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Mincho Georgiev

And definitely with surround effect, Mark  ::)