Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GC memory by Recycler reference counting #2

Closed
lishuai87 opened this issue Feb 13, 2018 · 1 comment
Closed

GC memory by Recycler reference counting #2

lishuai87 opened this issue Feb 13, 2018 · 1 comment

Comments

@lishuai87
Copy link

lishuai87 commented Feb 13, 2018

CoCo don't have garbage collection currently, so we have memory leak.

The PyObject.refCount may help if we call incRef,decRef when we need copy or delete PyObject.
But if we have circular reference, refCount won't work.
So we need GC strategy which can handle circular references. I'm trying to use Recycler:

[1] "A Pure Reference Counting Garbage Collector", 2001, Bacon, D. F., Attanasio, C. R., Rajan, V. T., Smith, S. E., & LEE, H.

https://github.com/thrunduil/cyclic_rc

#include "cyclic_rc/shared_ptr.h"

class PyObject;
using PyObjectPtr = cyclic_rc::shared_ptr<PyObject, false>;

class PyObject : public cyclic_rc::cyclic_rc_base<false> {
 public:
  PyObject();
  virtual ~PyObject();
  virtual void visit_children(int t) override {}
  PyObjectPtr callMethod(PyObjectPtr& my_ptr, string name, vector<PyObjectPtr>* args);
  ...
};

class PyList : public PyObject {
 public:
  void visit_children(int t) override {
    for (auto &i : data) {
      i.visit_children(t);
    }
  }

 protected:
  vector<PyObjectPtr> data;
};
@kentdlee
Copy link
Owner

This repository is for teaching and is an incomplete version of CoCo. A more robust JCoCo version written in Java is available. And, if C++ is your language, a more robust C++ version is available to college/university professors. If you are a college or university professor you can contact me at [email protected] and I will give you access to the full version of CoCo. In this student version which is used as the basis of assignments, garbage collection is not implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants