Article View: comp.windows.ms.programmer
Article #3431Memory management in protected mode
From: Peter Bergstrom
Date: Wed, 26 Jun 1991 14:25
Date: Wed, 26 Jun 1991 14:25
39 lines
2297 bytes
2297 bytes
I am trying to learn how to manage globally allocated memory and have been
working on a program that allocates a bunch of blocks and then deallocates
them. The outline of the program is to have two menu choices: Get and Release
that cause my program to GlobalAlloc and GlobalFree a chunk of memory. This
seems to work well (tracing using TDW shows the data structure being updated
correctly) until I exit. After I GlobalAlloc the block, I GlobalLock it in
place. Before I GlobalFree the block, I GlobalUnlock it. Each block is
Alloc,Lock,Unlock, and Free'd in the correct order.
The problem comes when I exit. It usually takes a few minutes, but Windows
always crashes, usually hard (Ctl-Alt-Del). This happens whether or not I
specifically release all the memory or let my WM_DESTROY message code free it
(it does the same thing for all the blocks that the Release menu choice does
for one.
I am baffled by this behavior - Metz' Freemem reports the correct amount of
memory free after my program exits (same as before), so I think it works OK.
I can't seem to trace through the WM_DESTROY message with TDW - it skips a
loop that *should* be working.
So, I have the following questions and/or thoughts that I would appreciate
comments on:
1) Does Windows reclaim the memory that a program allocates automatically?
2) Is it impossible to debug using TDW reliably (I can trace through all the
rest of the program)?
3) Do you have specific hints on how to effectively use global memory or
references to same?
Note: I own and *have read* Petzold, THE Guide, THE Reference and Richter's
Developer's Guide. I am really baffled by this and must learn more.
Thanks for any help,
Pete Bergstrom
UUCP: {amdahl!bungia, crash}!orbit!pnet51!peterb
ARPA: crash!orbit!pnet51!peterb@nosc.mil
INET: peterb@pnet51.orb.mn.org
Technical Details
Message-ID:
<5227@orbit.cts.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!cs.umn.edu!kksys!orbit!pnet51!peterbShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!cs.umn.edu!kksys!orbit!pnet51!peterb From: peterb@pnet51.orb.mn.org (Peter Bergstrom) Newsgroups: comp.windows.ms.programmer Subject: Memory management in protected mode Message-ID: <5227@orbit.cts.com> Date: 26 Jun 91 14:25:01 GMT Article-I.D.: orbit.5227 Sender: news@orbit.cts.com Organization: People-Net [pnet51], Minneapolis, MN. Lines: 39