Hello. I am trying to resolve a memory leak(s) in my app. I've downloaded and ran RedGate's ANTS Memory Profiler 5.0 and the memory profiler tells me the leak has to do with WeakReferences.
The problem I am running into is that I've never heard of a WeakReference nor are they explicitly declared in my app. From the reading I've done I b...
The Django docs say this on the subject:
Note also that Django stores signal
handlers as weak references by
default, so if your handler is a local
function, it may be garbage collected.
To prevent this, pass weak=False when
you call the signal’s connect().
I haven't been able to find any justification for why this is the ...
Hi,
In C#/.NET, is there any way to get a notification before the object pointed to by a weak reference is destructed? Basically, I want to allow an object to be collected, but do something right before the object is destroyed, without modifying code to add destructors (since I won't know exactly what types of objects will be sued with ...
Has anyone researched the runtime costs involved in creating and garbage collecting Java WeakReference objects? Are there any performance issues (e.g. contention) for multi-threaded applications?
EDIT: Obviously the actual answer(s) will be JVM dependent, but general observations are also welcome.
...
I have a reference to an object. This object has a timer event with a weak reference. Example:
timer.addEventListener(TimerEvent.TIMER, timerHandler, false, 0, true);
Now I remove this reference (test is the variable containing the reference):
test = null;
And yet, the timerHandler keeps being fired. Is this impossible, so that I m...
MySQLDb uses weak proxy to prevent circular dependencies between cursors and connections.
But you would expect from the documentation on weakref that you could still tests for equivalence. Yet:
In [36]: interactive.cursor.connection.thread_id()
Out[36]: 4267758
In [37]: interactive.web_logic.conns.primary.thread_id()
Out[37]: 4267758
...
I know that weak references are a good candidate for memoizing potentially large sets of data, and Wikipedia's article on weak references only lists "keeping track of the current variables being referenced in the application" and the statement "Another use of weak references is in writing a cache".
What are some other situations (more s...
In .NET 3.5, Does WeakReference work with String or shall I wrap it in a small "class" to make it work with it?
...
Hi,
In the code below I create a Pen object and initialize it's color to white. In the constructor of Pen, after setting the field 'penColor' to the value passed into the constructor, I update a global static weak hashmap that I'm keeping where the KEY is the 'this pointer - in my case a Pen, and the value is another weakhashmap whose ...
I've been reading up on garbage collection looking for features to include in my programming language and I came across "weak pointers". From here:
Weak pointers are like pointers,
except that references from weak
pointers do not prevent garbage
collection, and weak pointers must
have their validity checked before
they are...
Trying to set up a dependency in C++ with a parent-child relationship. The parent contains the child and the child has a weak pointer to the parent.
I would also like to be able to derive from the parent in Python. However, when I do this, I get a weak pointer error connecting up this parent-child relationship.
C++ code:
#include <boo...
I recently came across a piece of Java code with WeakReferences - I had never seen them deployed although I'd come across them when they were introduced. Is this something that should be routinely used or only when one runs into memory problems? If the latter, can they be easily retrofitted or does the code need serious refactoring? Can ...
i am trying to store some method callbacks but referring to it will keep the bound object alive, so i tried to keep a weakref to method but that doesn't seems to be possible?
so
Why can't i keep a weak ref. to method (see example below)
What is the best way to keep method ref? any thing in standard lib? Or I will have to keep function...
I have implemented abstract generic provider for notification bunch of generic listeners E, descendants have to override notifyListener(E) with specific notification code. For backing list of listeners I choose WeakHashMap<K,V>. Listeners must be held as weak references:
abstract public class NotificationProvider<E> {
private Map<E...
Java's WeakHashMap is often cited as being useful for caching. It seems odd though that its weak references are defined in terms of the map's keys, not its values. I mean, it's the values I want to cache, and which I want to get garbage collected once no-one else besides the cache is strongly referencing them, no?
In which way does it h...
What happens to the WeakReference when the target object referenced by WeakReference.Target has been garbage collected? Does the WeakRerence stay alive and keeps existing?
The reason why I am asking is that I have a list of WeakReferences stored in a List. During runtime new WeakReferences constantly are getting added to that list. Now w...
I'm considering to port an application to db4o. The data model consists of lots of small objects with a lot of references between each other. For example, I have a book which points to an author and chapter. Chapters have sections, sections have large blobs of text, images, and they reference characters mentioned.
I think it should be p...
I have a data model with a skeleton (metadata) and large data objects. I'd like to keep the skeleton in memory and hold weak references to the data objects. I understand how I would implement this with plain Java, how I would create a WeakHashMap and clean up etc. But I'm wondering what would be the best way to resurrect the data objects...
Hi everyone,
I'm currently coding a project in python where I need a sort of cache of generic objects, I have settled on using WeakValueDictionaries for this. These generic objects are often referenced by many other non-generic objects. My main problem though is that I can't seem to wrap my head around a way of making these WeakValueDic...
I've got a class Foo with a property Id. My goal is that there are no two instances of Foo with the same Id at the same time.
So I created a factory method CreateFoo which uses a cache in order to return the same instance for the same Id.
static Foo CreateFoo(int id) {
Foo foo;
if (!cache.TryGetValue(id, out foo)) {
foo...