Rob Dimeo (robert.dimeo@nist.gov) writes:
> I have been using XLOADCT in a widget program and I ran into a problem
> with leaking memory. When I run XLOADCT in a widget program where the
> top-level base of the widget program is the group leader for XLOADCT,
> quitting the widget program while XLOADCT is running SHOULD be
> seamless. However I consistently have leaking memory with the
> following in the output log:
>
> <PtrHeapVar391904>
> STRUCT = -> WIDGET_BUTTON Array[1]
The problem is that XLOADCT cleans up after itself if
you hit the DONE button, but not otherwise. This is
*exactly* why widget programs need CLEANUP routines that
get called when programs die! :-)
This problem is even more pernicious, since the pointer
that needs to get cleaned up is in a Common block, so you
can't even free it up with HEAP_GC!
Here is a cleanup routine for XLOADCT:
;*********************************************************
PRO xloadct_cleanup, id
COMMON colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
COMMON xloadct_com, r0, g0, b0, tfun, state, filename, cps, psave, pnt,
$
top, bot, silent, chop, lock, g_lbl, vbot, vtop, g_slider, $
gamma, color, use_values, ncolors, cbot, siz, w_height, show_win, $
updt_callback, p_updt_cb_data
if PTR_VALID(p_updt_cb_data) then PTR_FREE, p_updt_cb_data
END
;*********************************************************
Assign it like this:
XManager, "xloadct", base, NO_BLOCK=(NOT(FLOAT(block))), $
Cleanup='xloadct_cleanup'
That should do it. :-)
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
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
|