Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [weak-references]

A weak reference is a reference that does not protect the referenced object from deallocation

Filter by
Sorted by
Tagged with
1 vote
2 answers
131 views

Improvement suggestions to my shared_ptr and weak_ptr implementations

Below is the entire code. I appreciate if, someone with more C++ experience can suggest if this can be improved further and if you notice any issues. controlblock.hpp ...
user avatar
  • 135
11 votes
3 answers
634 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 ...
user avatar
2 votes
1 answer
79 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 ...
user avatar
  • 163
2 votes
1 answer
107 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 ...
user avatar
  • 71
2 votes
0 answers
94 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: ...
user avatar
  • 13.4k
12 votes
2 answers
1k 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 ...
user avatar
0 votes
1 answer
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 ...
user avatar
1 vote
2 answers
105 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-...
user avatar
  • 728
3 votes
0 answers
174 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 ...
user avatar
  • 185
3 votes
1 answer
2k 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 ...
user avatar
  • 181
1 vote
1 answer
210 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 ...
user avatar
  • 111
2 votes
1 answer
2k 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 ...
user avatar
5 votes
1 answer
3k views

Simple event manager in Java

I have created a simple event manager and I want it to work properly in a multithreaded environment: ...
user avatar
  • 171
2 votes
1 answer
152 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 ...
user avatar
4 votes
1 answer
230 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 ...
user avatar
  • 163
3 votes
1 answer
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 ...
user avatar
7 votes
2 answers
947 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 ...
user avatar
4 votes
1 answer
4k 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 ...
user avatar
1 vote
1 answer
921 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 ...
user avatar
  • 119
4 votes
1 answer
710 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 ...
user avatar
  • 745
5 votes
2 answers
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 ...
user avatar
  • 436
2 votes
1 answer
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 ...
user avatar
  • 368
4 votes
1 answer
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 ...