3 ms·
This is exactly the problem. In every reference counting system you need to know if a function will incrRefCount or not the passed argument, if you need to incr
by antirez 17y ago
This is exactly the problem. In every reference counting system you need to know if a function will incrRefCount or not the passed argument, if you need to increment it instead before to pass a new object, and things like this. One can try to have conventions but actually it is needed to know the behavior of other code in order to know if objects are reused, if one must pass objects that will be retained, if the object is expected to be already "safe" and will simply used and removed without to retain/release the reference.
For instance if you try to write a C extension for Python or Tcl or other systems using reference counting you'll notice that if you don't know every well the internals it can be not obvious when to increment or not the refcount.
I use refcount myself in Redis, and again for people not used to Redis internals to implement a new command may not be trivial exactly for this problem of reference counting. Reference counting is not something to expose for a language that aims to be a such an higher level. In short every language with complex OOP system should have some kind of automatic memory management IMHO.
- boucher 17y agoReference counting really isn't that hard to follow. Cocoa's conventions are pretty straightforward. You need to release (or autorelease -- which by the way is great) for every call to alloc, retain, copy (inc. fooCopy), or new (inc. newFoo). Everything else is autoreleased. Exceptions are documented.