Questions tagged [reference-counting]
8 questions
70
votes
3 answers
How does garbage collection compare to reference counting?
I starting working through an online course on iOS development in the new language from Apple, Swift. The instructor made a point that raised this question in my mind. He said something to the effect of:
There's no need to worry about memory…

Aaron Anodide
- 5,463
- 5
- 28
- 37
11
votes
5 answers
A reference counting pattern for memory managed languages?
Java and .NET have wonderful garbage collectors that manage memory for you, and convenient patterns for quickly releasing external objects (Closeable, IDisposable), but only if they are owned by a single object. In some systems a resource might…

C. Ross
- 2,926
- 2
- 26
- 42
6
votes
4 answers
Strategy for avoiding defensive copies while keeping correct encapsulation
I want to keep a dependency decoupled, but at the same time, once it's passed to the constructor, I want to allow changes only through Whatever (in the following example) because changing the dependency from the outside would invalidate the state of…

Wes
- 832
- 5
- 12
3
votes
3 answers
What is the best way to retain a local object which is performing an asynchronous task?
My problem is the following: inside a method I'm creating an object like this:
MyObject* myObject = [MyObject new];
Then I want it to perform an asynchronous task like this:
[myObject doSomethingAsyncWithCompletion:^{
//do something else upon…

Andrey Chernukha
- 109
- 8
3
votes
2 answers
COM - with great power comes great responsibility, but at what cost? (looking for advice on coding practices when working with COM)
What is best (or commonly accepted) practice for where to declare COM object variables (scope) and how to handle cleaning them up when using structured error handling?
I just spend a whole load of time learning about Garbage Collection and…

CBRF23
- 269
- 2
- 10
1
vote
2 answers
How is it that reference counting is faster on Apple silicon Intel translation than on Intel?
I can't find the exact tweet, but it was stated by Apple engineers that the retain and release operations are faster on Intel x86 translation than on standard Intel x86.

Curious
- 95
- 1
- 9
0
votes
2 answers
What's the canonical way to do compaction on a refcounted heap?
The only way I know of is to copy the whole heap by allocating copies of all objects on a new heap and dropping the old one, like couchbase db does for example. Presumably you could also do the same on a subset of the heap to copy less data around…

Filip Haglund
- 2,823
- 3
- 16
- 20
-1
votes
3 answers
I just used a goto statement. Is this OK?
I just wrote this code that uses a goto statement.
if (PyMethod_Check(attrib_value)) {
PyObject *im_self = PyObject_GetAttrString(attrib_value, "im_self");
if (im_self == Py_None) {
js_value = FunctionTemplate::New(isolate,…

tbodt
- 115
- 5