Questions tagged [weak-references]
A weak reference is a reference that does not protect the referenced object from deallocation
22
questions
10
votes
3answers
437 views
Simulated WeakReference class
I've created a fake WeakReference class for VBA by chance. A Weak Reference is not counted (i.e. IUnknown::AddRef method is not called). I knew about the Weak Reference concept from Swift and I ...
2
votes
1answer
64 views
Handling Rc pointers correctly in a parent/children tree
Needs
A container holds two collections: Parent instances and Child instances; their items can be searched by name;
A child can ...
2
votes
1answer
100 views
Preserving principle of locality while performing memory allocation
In order to implement an efficient AST visitor preserving the principle of locality, I implemented some reference counting mechanism in C++ with the following set of features:
All the newly allocated ...
2
votes
0answers
78 views
Loading weak cache in typescript
In Java, I use a LoadingCache which offers weakKeys
and I need something similar in Typescript, so I wrote the following:
...
11
votes
2answers
690 views
Solution for Parent/Child circular references: WeakReference class
Sometimes in advanced OOP scenarios, a class needs to hold instances of another class which needs to hold a reference to the "parent". For example when you have a dynamic ...
0
votes
1answer
2k views
WeakReference in AsyncTask
I want to use the WeakReference approach to not leak memory with my AsyncTask. I found examples online and on Stackoverflow, but ...
1
vote
2answers
92 views
Lightweight flexible observer framework using weak references
I found a need for a simple, generic publish-subscribe framework for my Java application. I looked over a few implementations on Code Review and I think mine avoids most of the pitfalls. Single-...
3
votes
0answers
154 views
F# Observable.subscribeWeakly implementation
In this SO question I needed an observable subscription function that can be used kind of like Observable.subscribe, but that does not keep a strong reference to ...
3
votes
1answer
1k views
Weak pointers to vector elements idea
I want to store some objects in linear memory, but sometimes I want to use these objects in some place for some time, but in the meantime object can be deleted, so I want to use weak_ptr's. This is my ...
1
vote
1answer
172 views
Class with multiple parameters as the object of a WeakReference
I just read this post on how to avoid memory leaks with AsyncTask. The post proposed using a WeakReference and supplying a TextView as the object of the WeakReference.
In my code, I need to supply ...
2
votes
1answer
1k views
Ensure that ICommand implementation properly uses weak references
I am building an implementation of System.Windows.Input.ICommand that is like the commonly used RelayCommand, but doesn't keep a ...
5
votes
1answer
2k views
Simple event manager in Java
I have created a simple event manager and I want it to work properly in a multithreaded environment:
...
2
votes
1answer
144 views
A nonstandard “shared pointer” of sorts
In a few of my projects, I had sort of a common situation, where I wanted to share a pointer to some object, and I want the recipient to be able to check if it is still valid, but I don't want them to ...
4
votes
1answer
189 views
Data Driven (ability) system
I am making a data drive system for creatures, abilities, items, etc. Considering my ability objects I need to create "templates" from the these since parsing them in real time is too slow. I am ...
3
votes
1answer
1k views
Minimal Map implementation with weak values
What follows is an implementation of the java.util.Map interface with weak values. This means that entries should be removed from the map when their values become ...
7
votes
2answers
910 views
Image cache for lots of images 2.0
Following from this question
I created a Image cache of sorts (let's call it version 1.0) that used WeakReference as "cache" items. And this comes from the ...
4
votes
1answer
3k views
Image cache for lots of images using WeakReference on C#
I'm developing an application to manage a player card-library from an online game. Each card has an image that is stored on disk with a numeric code, for example, the card with ID=1234 has his image ...
1
vote
1answer
846 views
A double mapped cache with WeakReferences for second key type
I needed a way to cache a large number of objects with two different types of keys.
In my case:
A String key represents my object in a serialized form. This way ...
4
votes
1answer
671 views
Generic 'temporary instance' class
I've been reading about WeakPointer and WeakPointer<T> today, and it looks very useful. Rather than just using it as-is ...
4
votes
2answers
1k views
“Removing” reference from its ReferenceQueue
Sometimes I need to ensure that some references won't be processed while examination from the associated ReferenceQueue. Generally at those moments I don't know ...
2
votes
1answer
3k views
Observer pattern in Java
I'm going to have a lot of integer values, and at any value change I might need to update any number of UI elements, other values which are computed from the first ones, etc. Sounds like time for the ...
4
votes
1answer
1k views
Wrapping bound methods
I've written this small class in Python that wraps bound methods but does not prevent the deletion of self.
Do you have any thoughts on my code?
Do you think I handle errors appropriately?
Is it ...