home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.misc
- Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!malgudi.oar.net!news.ans.net!cmcl2!panix!rryan
- From: rryan@panix.com (Rob Ryan)
- Subject: Re: Borland and Memory
- Message-ID: <1992Dec18.052959.6488@panix.com>
- Date: Fri, 18 Dec 1992 05:29:59 GMT
- Distribution: usa
- References: <BzAyI5.BrH@world.std.com> <1992Dec15.144205.16197@mksol.dseg.ti.com> <1992Dec16.182513.5844@panix.com> <1992Dec17.160015.24323@mksol.dseg.ti.com>
- Organization: Panix, NYC
- Lines: 35
-
- In <1992Dec17.160015.24323@mksol.dseg.ti.com> duitz@mksol.dseg.ti.com (mitchel n duitz) writes:
-
- >I'm using The Large Model in the program, and the allocation
- >works fine the first time I use the object, then when i delete
- >the object that uses all the memory, and try again it bombs.
- >I am freeing the memory delete[] pn. So I don;t know
- >what's going on. I even looped through with the debugger, and
- >then it got to a magic row and it locked up. Thanks.
-
- So, it sounds like the problem isn't in the allocation (because it works the
- first time) but the de-allocation. My understanding is that the construct
- "delete [] pn" is used for freeing the memory allocated with something like
- "int *pn = new int[100]". But if you're allocating memory for an array of
- pointers and then do subsequent allocations for arrays for the individual
- pointers in the first array to point to, don't you have to do something
- like:
-
- for (int i = 0; i < MAXX; i++)
- delete [] pn[i];
- delete [] pn;
-
- I personally find this sort of confusing, but it that seems like it should
- work. I don't know why "delete [] pn" by itself doesn't work (I could
- see it not freeing the bulk of the data, and destroying the pointers to
- a lot of data, but I don't see why that would be fatal). Perhaps when
- you're doing the next loop, the system runs out of memory, does a garbage
- collection (of sorts), but since the pointers for some unallocated data
- have been destroyed, it gets confused. Ideas?
-
- I really don't know and am just guessing, but does that make sense? Have
- I gone seriously awry here?
-
- --
- Rob Ryan
- rryan@panix.com
-