Python lammps.extract_fix and lammps_free

The description of lammps.extract_fix says it is a wrapper around lammps_extract_fix C-library function. The documentation for that C function says that the returned value has to be freed with lammps_free to avoid a memory leak. Is there an analogous operation that has to be done for the python function, or is that taken care of automatically?

This question is easily answered by looking at the python code in python/lammps/core.py.

[...]
    if fstyle == LMP_STYLE_GLOBAL:
      if ftype in (LMP_TYPE_SCALAR, LMP_TYPE_VECTOR, LMP_TYPE_ARRAY):
        self.lib.lammps_extract_fix.restype = POINTER(c_double)
        with ExceptionCheck(self):
          ptr = self.lib.lammps_extract_fix(self.lmp,fid,fstyle,ftype,nrow,ncol)
        result = ptr[0]
        self.lib.lammps_free(ptr)
        return result
      elif ftype in (LMP_SIZE_VECTOR, LMP_SIZE_ROWS, LMP_SIZE_COLS):
[...]

As you can see the call to lammps_free() is there and thus is not needed to be added manually. It is also a bit of a tricky business, as the lammps_free() call is not needed for all types of data that is extracted.

Thanks @akohlmey . I’ll take a look at the source next time.