A retain cycle is a situation in reference-counted memory management when two (or sometimes more) objects have strong references to each other. Normally, objects are destroyed when their reference count reaches zero, and the references they hold are released at that time. In a cycle, each object keeps the other alive, and neither will be destroyed unless the cycle is deliberately broken.
Questions tagged [retain-cycle]
301 questions
0
votes
3 answers
Block and retain cycle can't catch it
I've got an issue with blocks and weak reference, I'm under ARC. I built a class it is a free project that is a kind of easy wrapper around Google Directions API you can download it here:link to the project
Im'm using it inside a view controller…

Andrea
- 26,120
- 10
- 85
- 131
0
votes
1 answer
Does the absence of a "likely to lead to a retain cycle" warning imply a strong reference cycle will not be created?
Per the transitioning to ARC release notes, when referencing self within a block one should use weak references in order to avoid a strong reference/retain cycle:
MyViewController *myController = [[MyViewController alloc] init…];
//…

MaxGabriel
- 7,617
- 4
- 35
- 82
0
votes
2 answers
How to resolve retain cycle in block for void*?
I have a C++ static library that is linked in my iOS app. I have a void* to it in order to access some actions provided by the library from my code. The problem is that i have activated ARC on my project and it screams that in a block where the…

Sorin Antohi
- 6,145
- 9
- 45
- 71
0
votes
0 answers
Why does an ivar retain a block even after the ivar has been nilled?
We have a construct like this (ARC code):
// load an object into an ivar using a block
self->objectLoader = [MyObject loadOnSuccess:^(MyObject *object) {
// reference self from the block, so self is retained
self->_object = object;
//…

elijah
- 2,904
- 1
- 17
- 21
-1
votes
1 answer
How to use a class method as a closure without holding a strong reference to self in that method/closure?
I have a class :
class myVC:UIViewController {
let myButton = MyButton()
func viewDidLoad()
{
view.addSubview(myButton)
myButton.addTarget(myMethodClosure) // ***
}
func myMethodClosure() // I guess this…

Jerem Lachkar
- 1,008
- 11
- 24
-1
votes
2 answers
Why Does My App Crash due to Memory Issue?
I am dealing with an app created by some other developer. It's a complete app and has a lot of viewControllers , variables and outlets.
I keep getting the a crash after I load too many images from a server ( 200 for example ). I only get this…

Dyary
- 753
- 7
- 14
-1
votes
1 answer
Objective-C retain cycle between 2 objects
Here is the code:
TestA *ta = [[TestA alloc] init];
TestB *tb = [[TestB alloc] init];
ta.b = tb;
tb.a = ta;
I tried to set ta = nil or tb = nil. It didn't work but ta.b = nil worked. Why?

allentang
- 13
- 1
-1
votes
1 answer
How to avoid memory leaks with nested objects
imagine a Swift object A that has a reference to objects B and C, and that object B also has a reference to C as depicted in below:
Object A:
- Object B
- Object C
Object B:
- Object C
Assuming that all the references are strong, will this cause a…

Bruno Morgado
- 507
- 1
- 8
- 26
-1
votes
2 answers
self inside block called by super
In this case, weakself is needed to avoid retain cycle
[self showMethodA:^{
[weakself showMethodB];
}];
Will this case cause a retain cycle?
[super showMethodA:^{
[self showMethodB];
}];

Ted
- 22,696
- 11
- 95
- 109
-1
votes
2 answers
Explain Objective C retain cycle with real world example?
I am reading about retain cycle that, "A retain cycle can take a few forms, but it typically means that object A retains object B, and object B retains object A, but nothing else retains object A or B". But I'm not clear about that concepts. Please…

Dhiman Ranjit
- 81
- 2
- 12
-1
votes
1 answer
assign in NON-ARC and retain cycle
How retain cycle was tackled in NON-ARC !
I know assign is an alternative to weak.
weak will have its value set to nil If object allocated is deallocated whereas assign is not
so how it was done earlier can anybody help me understand

vinoth.kumar
- 92
- 12
-1
votes
1 answer
Which one of these would cause a retain cycle? (obj-c, sample code)
Still trying to get the hang of retain cycles when using blocks.
My question is.. which of the following (if any) would cause retain cycles?
1
[self.someProperty runSomeBlock:^{
[self.someOtherProperty doSomething];
}];
2
[self.someProperty…

Jiho Kang
- 2,482
- 1
- 28
- 38
-2
votes
3 answers
If a UIViewController is successfully de-allocated, no retain cycles?
I am trying to avoid retain cycles within my code and I had this question that i was not sure about. Any insights would be appreciated.
If a UIViewController is successfully de-allocated, does this also mean that all class objects within the…

user3013144
- 61
- 2
- 13
-2
votes
2 answers
In objective-c, by using self in a view controller, does this create a strong reference cycle?
I've noticed while working with Objective-C, the compiler throws error symbols enforcing the use of either self or an underscore when using a property which I think doesn't happen as harshly when using Swift. I'm now at the crossroads where I…

Laurence Wingo
- 3,912
- 7
- 33
- 61
-2
votes
2 answers
Swift - retain cycle not with self?
The question is really simple.
I know to detect retain cycles but i wanna know if in the next example i have retain cycle.
MainManager.sound.player.speak("1", didFinish: {
MainManager.sound.player.speak("3", didFinish: {
…

Asi Givati
- 1,348
- 1
- 15
- 31