gf_workspace

Purpose

getfem-matlab workspace management function.

Synopsis

gf_workspace('push') 
gf_workspace('pop' [,hobj i, hobj j,..])  
gf_workspace('stat') 
gf_workspace('stats')
gf_workspace('keep', hobj i[,hobj j, hobj k..]) 
gf_workspace('clear')
gf_workspace('clear all')
gf_workspace('class name', hobj i)

Description

Getfem uses its own workspaces in Matlab, independently of the matlab workspaces. The reason for that is the lack of a notion of destructor in matlab. Hence, only descriptors to the real object are manipulated in matlab workspaces, while the real data is managed by getfem++ functions. The getfem++ workspaces can be stacked with the commands 'push' and 'pop'. By default, all getfem variables belong to the root getfem workspace. A function can create its own workspace by invoking gf_workspace('push') at its beginning. When exiting, this function MUST invoke gf_workspace('pop') (you can use matlab exception handling to do this cleanly when the function exits on an error, see the example below).

gf_workspace('push') : create a new temporary workspace on the workspace stack.

gf_workspace('pop' [,i,j,..]) : leave the current workspace, destroying all getfem variables belonging to it, except the one listed after 'pop', and the ones which were moved to the parent workspace by gf_workspace('keep').

gf_workspace('stat') : print informations about variables in current workspace.

gf_workspace('stats') : print informations about all getfem variables.

gf_workspace('keep', i[,j,k..]) : prevent the listed variables i from being deleted when the command gf_workspace('pop') will be called. This is accomplished by moving this variable in the parent workspace.

gf_workspace('clear') : clear the current workspace.

gf_workspace('clear all') : clear every workspace, and return to the main workspace.

gf_workspace('class name', i) : return the class name of object i (if I is a mesh handle, it returns 'gfMesh' etc..).

Examples

If you want to create getfem-matlab object within one of your own m-files, you should follow this template in order to avoid memory leaks
function [a]=foo(x,y,z)
  gf_workspace('push');
  try
    ...                      % some work here ...
    a = gf_mesh_fem(m);      % create a  getfem$++$ object
    b = gf_mesh(x);
    gf_workspace('keep', a); % b will be automatically destroyed at the 'pop'
    ...                       % other work...
  catch
    gf_workspace('pop');     % cleanup before error
    error(lasterr);
  end;
  gf_workspace('pop');
You should be aware that this won't prevent memory leaks if you interrupt the function foo with Ctrl-C.

See Also