Fix some instances of reference rot by setting base attribute of arrays

Issue #151 open
Matthew Spellings created an issue

Currently, the arrays returned by freud (for example RDF.getRDF()) are invalidated in two cases:

  1. When the parent object (the RDF object in the example above) gets garbage collected
  2. When the arrays are reallocated (if you would be able to change rmax in the RDF, for example)

I think we should be able to prevent (1), at least, by setting the numpy.ndarray.base flag on the generated arrays to self (whichever compute object is generating them). Solving (2) is more complicated, but also not totally impossible I think.

An example of this sort of usage is at https://gist.github.com/GaelVaroquaux/1249305 .

Comments (10)

  1. Matthew Spellings reporter

    It looks like HOOMD snapshots still suffer from problem (2), but not (1).

    One solution to (2) would be to make a wrapper class in cython that looks like a numpy array and holds its own copy of a shared_ptr and then instantiate these wrapper classes inside the getX() methods all over freud.

  2. Eric Harper

    After taking a look at CubaticOP, I think the "freud" thing to do would be:

    1. create variables for returned tensors: m_sp_global_tensor, m_sp_cubatic_tensor
    2. update those and return in the "getX()" call
  3. Bradley Dice

    Before this issue is resolved, we should review the documentation and describe the proper approach to memory management in the developer guide.

  4. Log in to comment