comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: IDL Memory Leaks
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: IDL Memory Leaks [message #27678 is a reply to message #27677] Mon, 05 November 2001 10:22 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Myron Brown (brownmz1@jhuapl.edu) writes:

> Recently, I have noticed that my IDL programs leak memory, but I never
> use pointers directly. This is true when running with IDL on a Windows
> PC or on an SGI workstation. Widgets seem to be one source of
> problems. File I/O seems to be another, but I'm not yet sure. Due to
> the problems I'm having with memory leaks, my long runs eventually die
> when memory is exhausted.
>
> Does anyone have any hints on ways to avoid memory leaks in IDL?

Well, be *very* careful whose programs you use.
Those ones from that Coyote site are notorious
for having memory leaks. :-)

Having embarrassed myself with memory leaks far too
often for it to be amusing anymore, I have learned
a couple of things about the subject. Here are some
rules of thumb I use.

1. In widget programs put your clean-up routines
in a procedure that is called when the top-level
base dies. (In other words, use the CLEANUP keyword
to the XMANAGER call.) *Don't* put your clean-up
routines in a QUIT button event handler. People
don't exit your programs with the QUIT button!

2. Put your CLEANUP procedure (in widget or object
programs) VERY close to the GUI or INIT procedures
in your program file.

Most memory leaks come from adding a pointer to the
program somewhere during development and forgetting
to put the complementary cleanup in the CLEANUP
procedure. Having it very close by helps a lot.

3. Don't create a pointer without *immediately*
adding the line that cleans it up in the CLEANUP
routine (see 2, above).

4. If you are putting something new into a pointer,
always do this:

*ptr = somethingNew

Or, if you have to, this:

Ptr_Free, ptr
ptr = Ptr_New(somethingNew)

But, never this:

ptr = Ptr_New(somethingNew)

5. Before you show your program to *anyone*,
(a) start a new IDL session, (b) run your program,
(c) exit the program, and (d) type "HELP, /HEAP".
If anything exists on the heap, immediately read
steps 1-4 again.

That (and damn careful programming) should help. :-)

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: NETSCAPE BOMB - dont open/preview "Re: my pretty floor won't pour before I expect it"
Next Topic: FFT issues

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 14:53:35 PDT 2025

Total time taken to generate the page: 1.03989 seconds