weak-references

boost::weak_ptr interaction with custom deleter

I have a boost::shared_ptr with a custom deleter attached. When converting this to weak_ptr is the deleter information lost? If yes, how do I reattach the same deleter to shared_ptr-s acquired from weak_ptr::lock() method? The feature I am implementing is a container of weak_ptr-s pointing to the alive instances of some type. I need th...

How to create weak reference in Objective-C?

Hi, i have a situation like this: NSMutableArray * A = [[NSMutableArray alloc]initwithObjects:@"one",nil]; NSMutableArray * B = [[NSMutableArray alloc]initwithObjects:@"two",nil]; [A addObject:B]; [B addObject:A]; now here is a retain cycle, How can i break this retain cycle? (using weak reference)....in above example. Thanks ...

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

There are two ways (that I know of) to cause an unintentional memory leak in C#: Not disposing of resources that implement IDisposable Referencing and de-referencing events incorrectly. I don't really understand the second point. If the source object has a longer lifetime than the listener, and the listener doesn't need the events a...

WeakReference to Activity (Android)

In my Android app, when a user tries to transition from one activity to another, there may be some global state that indicates they need to complete some other action first. To accomplish this, I've written a class with the following code: private static WeakReference<Activity> oldActivityReference; private static Intent waitingIntent;...

Thread Safe Object Pool with Guarantee of Returning Existing Object if Strong References Exist?

I'm trying to extend the Clojure language to extend ACI-guaranteed refs to ACID-guaranteed drefs (durable refs). The API is to simply to call (dref key value), where key is a String of the key to be used in the underlying data store (BDB JE in my current implementation), and value is the Object that the dref should be initialized to. I...

differences between 'weak' and 'unowned' references in vala?

What are the differences between weak and unowned references in Vala. Based on what I've learned from Vala tutorials both weak and unowned references are not counted, and when the real instance goes out of scope they will refer to null(!!). Why there should be tow distinct means for one reason?(if they do the same job) If not, could so...

Why does exist WeakHashMap, but absent WeakSet?

Hi! From J. Bloch A ... source of memory leaks is listeners ... The best way to ensure that callbacks are garbage collected promptly is to store only weak references to them, for instance, by storing them only as keys in a WeakHashMap. So, why there isn't any WeakSet in java collection framework? Thanks. ...