[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pointer question

"Ted Graves" <egraves@socrates.Berkeley.EDU> wrote in message
> Hi all,
> Another lurker question ... let's say you define a pointer using the
> function and assign to a variable x.  As long as you keep track of x and
> reassign x and lose the pointer to the heap variable, things are great.
> can remove the heap variable from memory using the PTR_FREE procedure.
> But now let's say i have a function TEST that takes a pointer as an
> and i want to create a pointer on the fly to use in TEST.  So i do
> like
> result = TEST(PTR_NEW(value))
> where value is whatever i want the heap variable to be. What happens to
> heap variable assigned in this statement after TEST returns?  I'm assuming
> from that because of the way it was created, a heap variable now exists
that i
> can't easily get rid of without using HEAP_GC.


But if you have access to the code of TEST you could do this:

pro test, a

    ; Do something with a

    if not arg_present(a) then if ptr_valid(a) then ptr_free, a


Mark Hadfield
m.hadfield@niwa.cri.nz  http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research