weak-references

Suitable collection class for event listeners in Java

Related: http://stackoverflow.com/questions/1391918/does-java-have-a-linkedconcurrenthashmap-data-structure I am looking for a collection class to hold references to event listeners. Ideally I would like the collection to have the following properties (in order of priority): Maintains insertion order. The earlier listeners may can...

Weak reference callback is not called because of circular references

I'm trying to write a finalizer for Python classes that have circular references. I found out that weak reference callbacks are the way to go. Unfortunately, it seems the lambda I use as a callback is never called. For example, running this code: def del_A(name): print('An A deleted:' + name) class A(object): def __init__(self,...

How to do compare and increment atomically in C/C++

In my attempt to develope a thread-safe c++ weak pointer template class, I need to check a flag that indicating the object is still alive, if yes then increment the object's reference count and I need to do the both steps atomically. I know the existance of intrinsics functions provided by the compiler for instance _InterlockedCompareExc...

When to use weak references in Python?

Can anyone explain usage of weak references? The documentation doesn't explain it precisely, it just says that the GC can destroy the object linked to via a weak reference at any time. Then what's the point of having an object that can disappear at any time? What if I need to use it right after it disappeared? Can you please explain th...

Simple Data Caching using Weak References in WCF

Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string state) { var db = new LookUpRepository(); return db.GetCounties(state); } } class County { public string StateCode{get;set;} public string CountyName{get;set;} public int CountyCode{get;set;} } ...

weak references and garbage collection

Suppose I have a weak reference to a car which has an ordinary reference to an engine. No other references to the car or the engine exist. Can the engine be garbage collected? ...

Category on a weak linked object

I want to subclass or make a category of a weak linked object in Obj-C. MPMoviePlayerViewController is the subject here. MPMoviePlayerViewController is only available on 3.2 and later but I want to keep the compatibility of my app up to 3.0. What should I do? ...

AS3: Weak Listener References Not Appropriate During Initialization?

as i currently understand, if an event listener is added to an object with useWeakReference set to true, then it is eligible for garbage collection and will be removed if and when the garbage collection does a sweep. public function myCustomSpriteClass() //constructor { this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownList...

How does the Garbage Collector decide when to kill objects held by WeakReferences?

I have an object, which I believe is held only by a WeakReference. I've traced its reference holders using SOS and SOSEX, and both confirm that this is the case (I'm not an SOS expert, so I could be wrong on this point). The standard explanation of WeakReferences is that the GC ignores them when doing its sweeps. Nonetheless, my object ...

Lifetime issue of IDisposable unmanaged resources in a complex object graph?

This question is about dealing with unmanaged resources (COM interop) and making sure there won't be any resource leaks. I'd appreciate feedback on whether I seem to do things the right way. Background: Let's say I've got two classes: A class LimitedComResource which is a wrapper around a COM object (received via some API). There ...

Can a conforming C# compiler optimize away a local (but unused) variable if it is the only strong reference to an object?

or, in other words: Can an object referenced by a local variable be reclaimed before the variable goes out of scope (eg. because the variable is assigned, but then not used again), or is that object guaranteed to be ineligible for garbage collection until the variable goes out of scope? Let me explain: void Case_1(...

Good implementation of weak dictionary in .Net

Where can I find good implementation of IDictionary which uses weak references inside? Dictionary should be holding only weak references to values and eventually clean up itself of dead references. Or should I just write it myself? ...

Is there a way to do WeakList (think WeakReference) in CLR?

A List does not work in the way that I want. The way that I want is that WeakReferences are automatically removed from the list when the object they weakly reference is garbage collected. ConditionalWeakTable does not do what I want either, because although its keys and values are weakly referenced and collectable, you cannot enumerate ...

Cost to GC of using weak references in C#?

In another question, Stephen C says: A second concern is that there are runtime overheads with using weak references. The obvious costs are those of creating weak references and calling get on them. A less obvious cost is that significant extra work needs to be done each time the GC runs. So what exactly is the cost t...

Can I get a raw pointer from boost's weak_ptr?

Is it possible to get a raw pointer from boost::weak_ptr? Boost's shared_ptr has get() method and "->" operator. Is there some rationale behind weak_ptr not having the same functionality? ...

How to avoid memory leaks in callback?

Effective Java says: A third common source of memory leaks is listeners and other callbacks. If you implement an API where clients register callbacks but don’t deregister them explicitly, they will accumulate unless you take some action. The best way to ensure that callbacks are garbage collected promptly is to store ...

Relational Database with cache-like drop behaviour

I am looking for a database system that should be a relational database. But a main feature has to be that it forgets entries to fit a certain condition, like 'least recently used' on a certain size of the DB. In other words, I want a kind of 'weak reference' in a DB. Is there already such a solution? What do you think about that idea:...

Is there any class for weak References on iPhoneOS ==> none

My APP received a big data that was used about twice times. So, I think It`ll cause a memory problem. In this case I use the WeakReference class on java. But, I couldn`t find any class for weak references like java. Is there any class for weak refereces on iPhoneOS? Is this the only way in this case, that using didReceiveMemoryWarning...

One Liner: WeakReference-to-a-Lambda Event Handler

Hello, Can you see downsides to this one-liner other than the fact that multiple uses of it would violate the DRY principle? It seems straightforward but the fact that I haven't seen others propose it makes me wonder if there's a downside to it. This bit of code creates a WeakReference to a method and then registers an event handler th...

Understanding Java's Reference classes: SoftReference, WeakReference, and PhantomReference...

Can someone explain the difference between the three Reference classes (or post a link to a nice explanation)? SoftReference > WeakReference > PhantomReference, but when would I use each one? Why is there a WeakHashMap but no SoftHashMap or PhantomHashMap? And if I use the following code... WeakReference<String> ref = new WeakReference...