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

Home » Public Forums » archive » Re: Proper pointer cleanup question
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: Proper pointer cleanup question [message #34661 is a reply to message #34659] Tue, 08 April 2003 11:03 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
M. Katz (MKatz843@onebox.com) writes:

> Thanks! I'll write myself a full reverse-ordered cleanup routine.
> I suppose this explicit cleanup is just as important for objects as
> well:
> Object pointer fields should be explicitly freed in the Cleanup
> method.
>
> Question 1) But what about simple scalar pointers?
> a = ptr_new(fltarr(10,10))
>
> If I set
> a = 0
> Will I have stranded my fltarr(), or is IDL smart enough to deallocate
> it properly?

You will have leaking memory. IDL, as a weakly typed
language, always allows you to write dangerous code. :-)

> Question 2) Then how about this scenario
> a = ptr_new(fltarr(10,10))
> b = ptr_new(dblarr(5,5))
>
> a = b ;--- Does this strand the original a array?

Yes, for the same reason as above. You are re-defining A
before you have freed the memory the original pointer A
pointed to.

> *a = *b ;--- How about this?

This is perfectly OK. IDL handles pointer memory as it does
regular variable memory. Pointer A now points to the same data
as pointer B, but the memory pointer A originally pointed to
has been de-allocated by IDL.

> From looking at help, /memory and testing the above, I think the
> answer to both of my questions is that memory IS stranded unless you
> explicitly free it in all of the above cases.

No, *ptr = someNewData is always permissible. Just like
this is permissible:

a = 5
a = [10, 10]

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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Pb to work with huge files
Next Topic: Re: Where is the trick in objects

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

Current Time: Sat Oct 11 01:30:48 PDT 2025

Total time taken to generate the page: 1.84308 seconds