weak-references

How do you create a weak reference to an object in Python?

How do you create a weak reference to an object in Python? ...

When would you use a WeakHashMap or a WeakReference?

The use of weak references is something that I've never seen an implementation of so I'm trying to figure out what the use case for them is and how the implementation would work. When would you (or have you) had a need to use a WeakHashMap or WeakReference and how would it be used? ...

How to detect when an object is no longer referenced

Is there a way to create register a handler that will be called exactly at the time when the last reference to a certain object is released? An example would be an object that is backed by a physical data file and once the object become unreferenced, the file should be closed and than renamed. It would be nice if this was possible witho...

MovieClip isn't removed from Dictionary

I have a Dictionary where I hold data for movieclips, and I want the data to be garbage collected if I stop using the movieclips. I'm using the weak keys parameters, and it works perfectly with other data, however I've run into a problem. This code works great: var mc = new MovieClip(); var dic = new Dictionary(true); dic[mc] = 12; mc...

Create a weak reference to an object

Is it possible in Actionscript 3 to create a weak reference to an object, so that it can be garbage collected. I'm creating some classes to make debugging easier, so I don't want the objects to hang around in memory if they are only referenced here (and of course I don't want to fill the code with callbacks to remove the objects) ...

Is there a SoftHashMap in Java?

I know there is a WeakHashMap in java.util, but since it uses WeakReferences for everything, which is only referenced by this Map, referenced objects will get lost on the next GC cycle. So it's nearly useless if you want to cache random data, which is very likely to be requested again without being Hard-linked the rest of the time. The b...

Instance caching in Objective C

Hello! I want to cache the instances of a certain class. The class keeps a dictionary of all its instances and when somebody requests a new instance, the class tries to satisfy the request from the cache first. There is a small problem with memory management though: The dictionary cache retains the inserted objects, so that they never ge...

How to define an object whose address is null?

I am wondering how I can define an object in C whose reference will be null? // definition of foo ... void * bar = &foo; // bar must be null There is some ways I could find to do it, but none fit my needs. __attribute__((weak)) extern int foo; //not working with cygwin/gcc 3.4 __attribute__((at(0))) int foo; //only with rvds #...

Why doesn't the weakref work on this bound method?

I have a project where i'm trying to use weakrefs with callbacks, and I don't understand what I'm doing wrong. I have created simplified test that shows the exact behavior i'm confused with. Why is it that in this test test_a works as expected, but the weakref for self.MyCallbackB disappears between the class initialization and calling...

Equivalent to SoftReference in .net?

I am familiar with WeakReference, but I am looking for a reference type that is cleared only when memory is low, not simply every time when the gc runs (just like Java's SoftReference). I'm looking for a way to implement a memory-sensitive cache. ...

weakref list in python

I'm in need of a list of weak references that deletes items when they die. Currently the only way I have of doing this is to keep flushing the list (removing dead references manually). I'm aware there's a WeakKeyDictionary and a WeakValueDictionary, but I'm really after a WeakList, is there a way of doing this? Here's an example: impo...

Weak-keyed dictionary in Objective-C

Hello, I'm wondering if it's possible to have something similar to ActionScript 3's Dictionary object with weak keys in Objective-C. I want to be able to 'attach' an instance of a class to other arbitrary instances. Example; MetaData *meta = [MetaData metaDataForObject:someObject]; meta.whatever = foo; And later: foo = [MetaData me...

Create Weak Multimap with Google Collections

Is there an equivalent to the nice MapMaker for MultiMaps? currently i create the cache like this: public static Map<Session,List<Person>> personCache = new MapMaker().weakKeys().makeMap(); the whole point of MultiMap is to avoid the nested List Values. is there any way to construct the multimap with weak keys? ...

How are weak references implemented?

I wonder how weak references work internally, for example in .NET or in Java. My two general ideas are: "Intrusive" - to add list of weak references to the most top class (object class). Then, when an object is destroyed, all the weak references can be iterated and set to null. "Non-intrusive" - to maintain a hashtable of objects' poin...

NullReferenceException when function returns.

I am getting a NullReferenceException when running my multi-threaded application, but only when I run in Release mode outside of the debugger. The stack trace gets logged, and it always points to the same function call. I put several logging statements in the function to try to determine how far it would get, and every statement gets l...

finding weak reference objects in collections in java

A couple of questions regarding Java's WeakReference and Collections: Is there a library out there that implements Java's various data-set interfaces (eg Collection, List, Set, Queue etc) with WeakReference transparently? Like WeakHashMap is for the HashMap interface? Or is the common solution to simply create normal Collections and th...

Why is Visual Studio 2008 stuck in debug mode when compiling

I have a .NET project that for some reason gets stuck in debug mode. I've changed the compile mode from debug to release in the toolbar, but my project ends up in the debug directory anyway. Seems like VS is not updating the SLN file or something. Please help! The reason I am asking about this is because it seems that there are weak ref...

How to maintain a weak pointer to a parent in C++?

Is there a standard way of maintaining a weak pointer to a parent (which is created using a shared pointer) in a child object in C++? Essentially, I need to implement something on the lines of the following: Class B; Class A { ... private: B m_b; }; Class B { .... public: void SetParentPtr(const boost::shared_ptr<A>& a) { m_parentP...

I have a circular reference. How can I create a weak reference in Objective-C?

I have an object of class Row that needs to release numerous objects of the class Block. Every Block currently has a property that retains an instance variable of class Row. Every Row contains an NSMutableArray of these Blocks. I understand that this is a circular reference. Apple's documentation states that in order to deallocate an obj...

Weak events in .NET?

If object A listens to an event from object B, object B will keep object A alive. Is there a standard implementation of weak events that would prevent this? I know WPF has some mechanism but I am looking for something not tied to WPF. I am guessing the solution should use weak references somewhere. ...