Hi  Shing!

On 16 Jan., 18:18, Shing Hing Man <[email protected]> wrote:
> Hi,
>    In a Sage session (within notebook or command console) ,  how to
> list all the loaded objects and how to remove them from the session ?

AFAIK, it is the same as in Python, so, if you need references, it
would be the Python documentation.

The globally defined objects are in the dictionary "globals()".

sage: a=3
sage: globals()['a']
3

In other words, globals() is a dictionary, whose keys are the names of
the (globaly) defined objects, and returns these objects. Note that
even right after starting sage, globals().keys() is quite a long list.

Concerning "remove from the session": See http://docs.python.org/library/gc.html

Python keeps track on how many (direct or indirect) references are
made to an object. If you define an object and assign it to a variable
X, then X is a reference to that object. If you then do Y=X, there is
a second reference. If you "delete" X (del X), then it just means that
the number of references to the object decreases by one; hence, there
is still the reference from Y to the object, and fortunately that
prevents the object from being destroyed.

If there is no reference to the object left (or, more generally, if it
is impossible to come from the session to the object  by a chain of
references), then it is allowed to *really* destroy the object.

But that't the job of Python's garbage collector!
In other words, I think there is no need to actively remove anything.

Best regards,
Simon
-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to