Questions tagged [weak-references]

A weak reference is a one that makes no claim of ownership. A weak reference keeps a reference to the object in question while it is in memory, but does not prevent the memory management system from reclaiming the associated memory when the referenced object is otherwise no longer needed. Many languages feature or support various levels of weak references, such as Swift, Objective-C, Java, C#, Python, Perl and Lisp.

A weak reference is one that does not cause the memory management system to hold on to the referenced object. It is used in cases where one wants a reference to the object in question as long as it is still needed/used elsewhere, but to also not prevent it from being reclaimed by the memory management system in the course of its normal lifecycle.

Weak references are especially important where one might have two or more objects referencing each other and you want to avoid a “retain cycle” or ”strong reference cycle”, where circular combinations of strong references will prevent the memory from ever being reclaimed. One common use of weak references in conjunction with closures and callbacks.

Some garbage-collected languages feature or support various levels of weak references, such as , , , and .

Reference counting languages, such as and , use weak (and unowned) references to prevent the establishment of additional strong references. An object that has no further strong references will be deallocated.

Certain environments have further variations on weak references such as "soft", "unowned", "phantom", which have very specific meanings in those environments.

1131 questions
0
votes
1 answer

Why ButtonBase doesn't check its Visibility before testing `ICommand.CanExecute`?

I've faced with an issue, that blows up my mind. Let's look at these methods from ButtonBase: private void HookCommand(ICommand command) { CanExecuteChangedEventManager.AddHandler(command, OnCanExecuteChanged); …
Dennis
  • 37,026
  • 10
  • 82
  • 150
0
votes
0 answers

weak node js module error on windows 7

I have installed all the necessary requirements for the node-gyp for windows 7 from the link below https://github.com/TooTallNate/node-gyp I am trying to install weak nodeJS module , but I am facing the below error weakref.obj : error LNK2001:…
CrazyNooB
  • 1,553
  • 3
  • 17
  • 23
0
votes
2 answers

Which storage (weak or strong) for the elements underneath the "main" View in iOS7

After reading really many books and docs on iOS programming I am still confused - which Storage type (weak or strong) to select, when control dragging from a UI element underneath the "main" View? (and by "main" I think I mean the UIView assigned to…
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
0
votes
1 answer

Is this still WeakReference?

I am creating a WeakReference and keeping it somewhere. WeakReference mWeakReference = new WeakReference(new MySpecialObject("My","Special","Data")); But some other external library(which I don't what it is doing…
guness
  • 6,336
  • 7
  • 59
  • 88
0
votes
3 answers

Return object to pool when no references point to it

Ok, I want to do the following to me it seems like a good idea so if there's no way to do what I'm asking, I'm sure there's a reasonable alternative. Anyways, I have a sparse matrix. It's pretty big and mostly empty. I have a class called MatrixNode…
Luka Horvat
  • 4,283
  • 3
  • 30
  • 48
0
votes
1 answer

Avoid redefinition of alias variable for weak reference in header-file

I have a variable in an header file: myHeader.h uint16 dummyVar = 0; extern const uint16 myVar __attribute__((weak,alias("dummyVar"))); So when I don't link the parts where myVar gets defined, the linker will just give it the value of the symbol…
Toby
  • 3,815
  • 14
  • 51
  • 67
0
votes
2 answers

AsyncTask optimization regarding internal list

People , I have an async task which downloads some news items using a webservice . Here is the psuedo for that . I have an operation that i perform in an asynctask . It downloads some news from a webservice . AsyncTask { AsyncTask(Context…
Muhammad Ahmed AbuTalib
  • 4,080
  • 4
  • 36
  • 59
0
votes
1 answer

Can I change attributes from a symbol (function) in another c-File?

I try to keep this as simple as I can (even tho I have a relating question running, but this is supposed to be more general. When I declare a function extern void foo(void) with a prototype and call it in the same C-File, can I give it the attribute…
Toby
  • 3,815
  • 14
  • 51
  • 67
0
votes
2 answers

Objective C - Two Dictionaries using same values, strong or weak

I'm new to objective c and I've got an interesting situation where I need two different NSDictionary objects that point to the same values. In that situation should I use strong or weak in the property declaration? Or should I do strong in one and…
CamHart
  • 3,825
  • 7
  • 33
  • 69
0
votes
1 answer

OS X: How to make dictionary with weak refs to objects on 10.7, ARC enabled

How can one create a dictionary of objects with weak references -- that is, the dictionary does not retain its keys and values -- on OS X 10.7 with ARC enabled? NSMapTable looks promising but unfortunately it doesn't use weak references when ARC is…
Steveo
  • 2,238
  • 1
  • 21
  • 34
0
votes
1 answer

What are WeakReferences, Weakhashmaps, softreferences used for?

Please explain what WeakReferences are used for. I usually do understand Java concepts, but this one is giving me trouble. I do understand what WeakReferences are, but their usage and nature is a little vague inside my head. I am not able to…
0
votes
1 answer

Caching big children in data model with db4o

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…
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
0
votes
2 answers

Can/should I use WeakReference in my complex object structure with db4o?

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…
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
0
votes
1 answer

Crash with iAd only on iOS 7 - weak delegate is bad pointer

I'm getting a strange crash with the iAd error callback. Here is my crash log: Exception Type: EXC_BAD_ACCESS Code: KERN_INVALID_ADDRESS at 0x2281 0com.apple.main-thread Crashed 0 libobjc.A.dylib objc_retain + 17 1 YouDoodle AdView.m line…
jjxtra
  • 20,415
  • 16
  • 100
  • 140
0
votes
2 answers

__block : Assigning a variable inside a block to an outside variable does not work

following the recommendations found here, I wrote the following piece of code: __weak __block NSMutableArray *articlesArray = nil; // I'm using ARC AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL…
Luis
  • 447
  • 1
  • 7
  • 24