Re: Why are objects global? [message #20687] |
Wed, 19 July 2000 00:00  |
Martin Schultz
Messages: 515 Registered: August 1997
|
Senior Member |
|
|
bjackel@phys.ucalgary.ca wrote:
>
> Subject line says it all.
>
> I've been playing with objects (not object graphics) for a
> while now, and can see how they might be useful. However,
> having to call "obj_destroy" manually at the end of functions
> and routines has been the source of many headaches.
>
> For example, consider the procedure below. It creates
> a "vector3" object which is used for various useful
> calculations, but is of no further use outside "example".
> Once we exit "example", variables "a" and "b" are automatically
> cleaned up. However, "c" gets leaked, unless we explicitly
> destroy it.
>
> Previously, variables in routines would be local unless
> 1) linked to a parameter or keyword
> 2) placed in a common block
> 3) attached to a pointer
>
> Why must objects be any different?
>
> I would argue that they should be treated the same as
> any other variables: cleaned up at the end of a procedure
> or function, unless one of the three conditions mentioned
> above is met. The current behaviour adds complexity to
> IDL, with no obvious advantages.
>
> Brian
>
>
ok. Consider the following: You create a container object somwhere
within a program,
then you call a subroutine to create some object which shall be stored
in the
container. Although that object is never passed into or out of the
routine, you
certainly want to keep it "alive":
; pseudo example
pro make_contents, theContainer
; theContainer is the object reference of the container object
rectangle = obj_new('grSymbol',bounds=,[0.,0.,1.,1.])
theContainer->Add(rectangle)
end
; main
theContainer = obj_new('IDL_Container')
make_contents,theContainer
help,theContainer->Get(index=0)
end
Martin
--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
[[ Bundesstr. 55, 20146 Hamburg [[
[[ phone: +49 40 41173-308 [[
[[ fax: +49 40 41173-298 [[
[[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
|
|
|