reference-counting

Reference counting in Cocoa

Hi, I assume according to "Cocoa design patterns" book i'm reading that the retain function is implemented using something like this : - (int)retainCount // Returns the receiver's current reference count { int result = 1; // receiver not in table, its count is 1 void *tableValue = NSMapGet( [[self class] _myRefCountMapTable], self);...

Synchronization primitive for shared usage counter?

Is there a Windows (or .NET) synchronization primitive that: can be shared across multiple processes on the same PC; represents a counter of how many threads are currently depending on a shared resource; is automatically decremented by the OS when a process abnormally terminates; and can be waited on by another process (and signaled wh...

Reference-counting of std::string

I'm looking at the code for basic_string (that is bundled with g++ 4.2.1). The copy constructor makes use of a grab() function to "grab" a copy of a string (increment its reference-count): _CharT* _M_grab( const _Alloc& __alloc1, const _Alloc& __alloc2 ) { return (!_M_is_leaked() && __alloc1 == __alloc2) ? _M_refcopy() : _M_clone(__a...

boost::shared_ptr cycle break with weak_ptr

I am currently in a situation like: struct A { shared_ptr< B > b; } struct B { shared_ptr< A > a; } shared_ptr< A > a(new A()); shared_ptr< B > b(new B(); a->b(b); b->a(a); I know this won't work, because the references would continue to point to each other. I've also been told that weak_ptr solves this issue. However, weak ptr has no...

What is the difference between Garbage Collection and Reference Counting in Mac OS

What is the difference between Garbage Collection and Reference Counting in Mac OS X. Thanks and regards. Mahadevan S ...

Simple reference counting: smart pointers

I would like to implement a simple reference counting using smart pointers. The variable pointer represents pointer to stored object, reference_count represents total count of copies of the object. if we initialize an object using NULL: reference_count = -1 else reference_count = 1 copy ctor and operator = increment reference_count des...

Smart pointers, or "better" destructor

Which type of the smart pointer (shared, scoped) would be for such a data structures the most suitable... Structure 1: //Class with cross-references to points p1, p2 class PointTopo { private: double x, y; PointTopo * p1; PointTopo * p2; public: PointTopo(double xx, double yy): x(xx), y(yy) {this-> p1 = NULL; this->p...

What does cpython do to help detect object cycles(reference counting)?

From what I've read about cpython it seems like it does reference counting + something extra to detect/free objects pointing to each other.(Correct me if I'm wrong). Could someone explain the something extra? Also does this guarantee* no cycle leaking? If not is there any research into an algorithm proven to add to reference counting to ...

Why aren't _AddRef and _Release called on my Delphi object?

I'm really confused. // initial class type TTestClass = class( TInterfacedObject) end; {...} // test procedure procedure testMF(); var c1, c2 : TTestClass; begin c1 := TTestClass.Create(); // create, addref c2 := c1; // addref c1 := nil; // refcount - 1 MessageBox( 0, pchar( inttostr( c2.refcount...

Python reference count and ctypes

Hallo, I have some troubles understanding the python reference count. What I want to do is return a tuple from c++ to python using the ctypes module. C++: PyObject* foo(...) { ... return Py_BuildValue("(s, s)", value1, value2); } Python: pointer = c_foo(...) # c_foo loaded with ctypes obj = cast(pointer, py_object).value I'm...