What is the difference between a __weak and a __block reference?

From the docs about __block __block variables live in storage that is shared between the lexical scope of the variable and all blocks and block copies declared or created within the variable’s lexical scope. Thus, the storage will survive the destruction of the stack frame if any copies of the blocks declared within the frame … Read more

How to delete every reference of an object in Python?

No no no. Python has a garbage collector that has very strong territory issues – it won’t mess with you creating objects, you don’t mess with it deleting objects. Simply put, it can’t be done, and for a good reason. If, for instance, your need comes from cases of, say, caching algorithms that keep references, … Read more

Is Josh Smith’s implementation of the RelayCommand flawed?

I’ve found the answer in Josh’s comment on his “Understanding Routed Commands” article: […] you have to use the WeakEvent pattern in your CanExecuteChanged event. This is because visual elements will hook that event, and since the command object might never be garbage collected until the app shuts down, there is a very real potential … Read more

How does weak_ptr work?

shared_ptr uses an extra “counter” object (aka. “shared count” or “control block”) to store the reference count. (BTW: that “counter” object also stores the deleter.) Every shared_ptr and weak_ptr contains a pointer to the actual pointee, and a second pointer to the “counter” object. To implement weak_ptr, the “counter” object stores two different counters: The … Read more

Weak NSString variable is not nil after setting the only strong reference to nil

tl; dr: The problem is that the string literal never gets released so your weak pointer still points to it. Theory Strong variables will retain the value they point to. Weak variables won’t retain their value and when the value is deallocated they will set their pointer to nil (to be safe). Unsafe unretained values … Read more

How do events cause memory leaks in C# and how do Weak References help mitigate that?

When a listener attaches an event listener to an event, the source object will get a reference to the listener object. This means that the listener cannot be collected by the garbage collector until either the event handler is detached, or the source object is collected. Consider the following classes: class Source { public event … Read more

Is it possible to create a “weak reference” in JavaScript?

Update: Since July, 2020 some implementations (Chrome, Edge, Firefox and Node.js) has had support for WeakRefs as defined in the WeakRefs proposal, which is a “Stage 3 Draft” as of December 16, 2020. There is no language support for weakrefs in JavaScript. You can roll your own using manual reference counting, but not especially smoothly. … Read more

Bitmap, Bitmap.recycle(), WeakReferences, and Garbage Collection

Bitmap.recycle isn’t required to be called, as the garbage collector will clean up bitmaps on its own eventually (as long as there are no references). Bitmaps in Android are created in native memory, not on the VM heap, so the actual bitmap object on the VM heap is very small as it doesn’t contain any … Read more

Where does the weak self go?

First of all, note that you generally don’t need to worry about retain cycles with DispatchQueue.main.asyncAfter, as the closure will be executed at some point. Therefore whether or not you weakly capture self, you won’t be creating a permanent retain cycle (assuming that tickle.fresh also doesn’t). Whether or not you put a [weak self] capture … Read more