|
Mark gave some excellent standards for dealing with lists.
One good way to ensure you delete a list and reset the list id is to do
this:
if somelist >0 and listlen(somelist)>=0 then somelist=dellist(somelist);
DelList() returns a 0 if successful, and is good candidate value for an
'ex-list' id.
I typically use a less robust (but will move up to the more robust use of
listlen() )
if somelist then somelist=dellist(somelist);
To simplify the whole concept, macroize it (the macro can be defined
anywhere (even in the SCL), I suggest an autocall library)
%macro DELLIST (aList,recurse=N);
if &aList > 0 and listlen (&aList) >= 0 then &aList = dellist
(&aList,&recurse);
%mend;
...
a=makelist();
b=makelist();
c=makelist();
...
%dellist (a)
%dellist (b)
%dellist (c)
I leave the exercise of replacing <aList> (macro var containing one variable
name [whose value is a list id]) with <lists> (macro var containing space
separated list of variable names [whose values are list ids]) to the
curious.
"Mark Bodt" <markbodt@STSS.CO.NZ> wrote in message
news:3.0.5.32.19991218144914.015c2a50@pop3.paradise.net.nz...
> At 12:30 17/12/99 -0500, you wrote:
> >SAS-L,
> > I recently became aware of the fact that SCL lists remain in memory
> unless explicitly deleted. What prompted me to discover this fact was
> >the observation that one SCL entry was eating LOTS of RAM because of
> >a huge list that I created. I am writing the SCL code to execute on a
> >server where many SAS sessions may be running, so efficiency is of
> >utmost importance. Are there any other issues that I could be
> >unpleasantly surprised with in terms of memory use or processor speed?
> >In general, what are some tips on how to write efficient SCL code?
> >Are there any books?
> >
> >Thanks,
> >David Ward
> >
> >
> >--
> >--------------------------------------
> >David L. Ward, Senior Software Developer
> >DZS Software Solutions, Inc.
> >Bound Brook, NJ
> >SAS Related: dward@sashelp.com
> >Work Related: dward@dzs.com
> >--------------------------------------
> >--
> >
>
> David,
> below is a tip I posted some time (years?) ago.
>
> Memory Leaks and deleting lists without errors.
>
> When you work with SCL lists, they are held in memory. If a program or
> method creates a list, but does not delete it on termination and the
> program or method is repeatedly called then available memory will
> progressively diminish. This phenomenon is called a memory leak. It is
> therefore crucial to ensure that lists are removed from memory when they
> are no longer required.
>
> To delete a list use the function: rc=dellist(listid);
>
> Where listid is the list identifier of the list you wish to delete. Note
> that if the list identifier is invalid then a program halt will occur. To
> avoid this situation, the listlen(listid) function can be used in the
> following way:
>
> If listlen(listid)>=0 then rc=dellist(listid);
>
> The listlen function returns the length of the list identified in the
> variable listid . If the list is empty then it will return 0. If the list
> has items it, then the function will return the number of items. If the
> list is invalid then a negative value is returned.
>
> It is also could practice to said the list identifier to missing up the
> list has been deleted. The reason for this is that SAS may recycle the
> number used to identify the list. Consider the following code:
>
> *create a list;
> List1=makelist();
>
> *code to insert some items into the list;
>
> *delete the first list;
> If listlen(list1)>=0 then rc=dellist(list1);
>
> /*Note that the first list has been deleted, but the list identifier list1
> still contains a number which used to point to list1 */
>
> *create a new list called list 2;
> List2=makelist();
>
> *try to delete list1 again;
> If listlen(list1)>=0 then rc=dellist(list1);
>
> When list2 was created, SAS may have recycled the list identifier. This
> means that the variables list1 and list2 may have the same number. When
an
> attempt is made to delete list1 again, because list1 and list2 contain the
> same identifier, then list 2 is deleted in error. By adding the line
>
> Listid=.;
>
> Immediately after deleting list1, we remove any references to any new
lists
> that are created.
>
>
>
> HTH
>
>
> Mark
>
>
> +------------------------------------------+--------------------------+
> | Mark Bodt | |
> | Sunken Treasure Software Systems Ltd | SAS Institute(NZ) Ltd. |
> | Specialising in SAS(R) Software | Quality Partner. |
> | Consultancy in the Asia / Pacific Region | |
> +------------------------------------------+--------------------------+
> | PO Box 9472, Marion Square, Wellington, New Zealand |
> | Ph (025) 725 386 Fax +64 4 385 8670 Email: markbodt@stss.co.nz |
> +---------------------------------------------------------------------+
|