Questions tagged [weak]
128 questions
37
votes
6 answers
Using as a concrete type conforming to protocol AnyObject is not supported
I'm using Swift 2 and using WeakContainer as a way to store a set of weak objects, much like NSHashTable.weakObjectsHashTable()
struct WeakContainer {
weak var value: T?
}
public protocol MyDelegate : AnyObject {
}
Then in my…

onmyway133
- 45,645
- 31
- 257
- 263
30
votes
4 answers
What exactly does '__weak typeof(self)weakSelf = self;' mean
This is used in the weakify pattern of Objective-C
My guess is that it means: assign a weak reference to self with the name 'weakSelf' and the typeof self (e.g. MyViewController)
If it's correct and looks obvious to you: I want to be absolutely sure…

brainray
- 12,512
- 11
- 67
- 116
28
votes
5 answers
How to make weak linking work with GCC?
There seem to be 3 ways of telling GCC to weak link a symbol:
__attribute__((weak_import))
__attribute__((weak))
#pragma weak symbol_name
None of these work for me:
#pragma weak asdf
extern void asdf(void) __attribute__((weak_import,…
Ben
23
votes
2 answers
how to make a weak pointer to self in swift outside of a block
i want to make a weak pointer to self in swift like how we used to in objective-c like
__weak Something *weakself = self;
I have found people explaining how to use a 'weak self' inside a block,
{ in [unowned self] ...}
but i dont want to…

user1709076
- 2,538
- 9
- 38
- 59
21
votes
1 answer
IBOutlet for NSTextView in a ARC project
As you read here in most cases a IBOutlet should be weak.
Now as you can read in the development library not all classes support weak references.
(e.g. NSTextView). This means you have to use assign:
@property (assign) IBOutlet NSTextView…

Stephan
- 4,263
- 2
- 24
- 33
20
votes
2 answers
Swift dictionary with weak reference keys?
Let's say I have a some objects representing network connections. Once these connections are disconnected, the associated objects disappear. I don't want to hang on to a connection object which is no longer connected.
I also want to associate some…
user1002430
17
votes
4 answers
Is there a boost::weak_intrusive_pointer?
For legacy reasons I need to use intrusive pointers, as I need the ability to convert raw pointers to smart pointers.
However I noticed there is no weak intrusive pointer for boost. I did find a talk about it on the boost thread list, however…

Rich
- 3,722
- 5
- 33
- 47
11
votes
1 answer
Weak symbol link on Mac OS X
Currently I encountered a weak link issue on Mac OS X 10.6.7 with Xcode 4.0.2.
$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
As the developer document said, we can use gcc attribute((weak_import)) for…

Robin
- 643
- 4
- 10
10
votes
4 answers
What is the proper way to avoid Retain Cycle while using blocks
What is the proper way to add objects in NSMutableArray which is strongly defined by property.
[tapBlockView setTapBlock:^(UIImage* image) {
[self.myImageArray addObject:image]; // self retain cycle
}
If I will create weak reference something…

Tariq
- 9,861
- 12
- 62
- 103
8
votes
3 answers
Is it the right way using `[weak self]` in swift closure?
I always using [weak self] in swift closure to prevent reference cycle.
Here is the code below, is it the correct way?
someTask(completion: {[weak self] (result) in
if self == nil {
return
}
//is it safe when…

James Zhang
- 95
- 1
- 4
8
votes
1 answer
Delphi: Object aggregation and memory leaks using [weak] attribute
I want to build a class TParent containing several child objects by using aggregation. Some of the objects are independant, while some can be also dependant on the other children. All the children objects have to have a reference to the parent. I…

VyPu
- 83
- 5
8
votes
0 answers
Xcode 7, duplicate identical addresses for weak pointers
I am a little confused by something I am seeing in Xcode 7, the 3 colors below all have a separate address as you would expect, but the weak colors all have the same address. I understand that the weak colors are optionals so weak_R and color_R have…

fuzzygoat
- 26,573
- 48
- 165
- 294
7
votes
0 answers
GCC optimization bug on weak const variable
I'm getting a weird gcc behaviour when dealing with weak const variables on different optimize levels (i.e. -O0 or -O1).
Here is the code:
def.h: declarations
const int var;
int copy;
int do_copy(void);
weak.c: weak var definition, do_copy…

Lrnt Gr
- 369
- 2
- 9
7
votes
4 answers
How I can make alias on external defined function in C?
During compiling this C code
extern void Default_Handler(void);
void NMI_Handler(void) __attribute__ ((weak, alias ("Default_Handler")));
I've recive this
error: 'NMI_Handler' aliased to undefined symbol 'Default_Handler'
How I can make alias on…

Immortal_Buka
- 79
- 2
- 5
7
votes
1 answer
Difference between weak self vs weak self()
What is the difference between passing [weak self] as an argument to a closure vs passing [weak self] ()
For example :
dispatch_async(dispatch_get_main_queue()) { [weak self] in
//Some code here
}
v/s…

Samkit Jain
- 2,523
- 16
- 33