Questions tagged [retain-cycle]

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.

301 questions
0
votes
1 answer

Retain cycle Objective C with 3 objects

I have 3 objects - a ViewController, another VC that is the strong property of the ViewController (call it VC2), and a class called "Checker" that checks to see if an action occurred in VC2. "Checker" is just a class with class methods - no instance…
noobsmcgoobs
  • 2,716
  • 5
  • 32
  • 52
0
votes
1 answer

Swift Passing Class Method as Parameter vs Closure

I have a question regarding a potential retain cycle in a given situation. public struct MasterItem { public let itemTitle: String! public var itemImage: UIImage? public let itemCallback: ((MasterItem) -> Void)! public let ord:…
drfear
  • 121
  • 1
  • 7
0
votes
3 answers

RetainCycle with Globals

Let's say in iOS we have: In W2AppDelegate.m: GlobalViewController *globalVc; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... } In SomeOtherViewController.m: - (void)viewDidLoad…
LB.
  • 13,730
  • 24
  • 67
  • 102
0
votes
2 answers

Calling Dealloc method in sprite kit

As a test to ensure that scenes are being dealloc'd i've been adding the: -(void)dealloc{ NSLog(@"scenename Dealloc); } I've noticed that sometimes this method isn't called, i had previous issues with retain cycles which i believe i fixed, the…
SmokersCough
  • 967
  • 7
  • 22
0
votes
1 answer

iOS datasource and outlet references

I viewed some Stanford iOS development classes on Youtube, and I found something that's not clear to me. In the lecture the professor explains how to create custom views and custom data source classes, and the code is the…
user2340612
  • 10,053
  • 4
  • 41
  • 66
0
votes
3 answers

Do I need a strongSelf in block to keep self alive and does the strongSelf really work?

This is what I have learned: when using self retained block I need a weakSelf to break retain cycle I need a strongSelf to prevent self from becoming nil half-way so I want to test if a strongSelf can really keep self alive like…
dopcn
  • 4,218
  • 3
  • 23
  • 32
0
votes
1 answer

Why putting "self" in the GCD blocks will cause a memory leak?

I have read the great article write by benzado that using block will cause memory leak if we have a class variable retain the block itself, and the block retain "self", that cause a retain cycle. How do I avoid capturing self in blocks when…
林鼎棋
  • 1,995
  • 2
  • 16
  • 25
0
votes
0 answers

How to properly keep a local reference to a child CCNode in a custom class in ARC

So, I want to hold a local reference to a child CCNode in a CCNode custom class without creating a retain cycle or without having the compiler complaining that the property or instance variable may be unpredictable set to nil For instance with this…
rraallvv
  • 2,875
  • 6
  • 30
  • 67
0
votes
2 answers

Retain cycles and Instruments

I just wrote this retain cycle: #import #import "Driver.h" #import "Car.h" int main(int argc, const char * argv[]) { @autoreleasepool { Driver *driver = [[Driver alloc] init]; Car *car = [[Car alloc]…
pedro
  • 73
  • 1
  • 6
0
votes
1 answer

would this cause a retain cycle

xCode 5.1, iOS 7.1, ARC Would this cause a retain cycle on topics? I don't think so, as setting event=nil will deallocate the whole tree, so topics will also get deallocated, but I am not sure. event -> subEvent -> Topics | ^ …
inforeqd
  • 3,209
  • 6
  • 32
  • 46
0
votes
2 answers

How does this prevent block retain cycles?

I saw a solution to preventing block retain cycles here But I am having trouble wrapping my head around why or even how it works. In the example, a weak self reference is made and acted upon. I can see how this Breaks the cycle. However, within…
DerrickHo328
  • 4,664
  • 7
  • 29
  • 50
0
votes
1 answer

uiviewcontroller still retaining after remove from superview, is it retain cycle issue

i have a UIViewController subclass ABCViewController.On a button long press, I open a UIPopover containing a UIViewController(AddProduct) On abuton long press.The add product contains a cancel button which brings user back to ABCViewControl.and in…
maddy
  • 4,001
  • 8
  • 42
  • 65
0
votes
2 answers

Understanding a subtle retain cycle with blocks under ARC

I'm studying a code snippet I grabbed from Effective Objective-C book by Matt Galloway. The snippet is the following (I've modified a little bit). - (void)downloadData { NSURL *url = // alloc-init NetworkFetcher *networkFetcher = …
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
0
votes
2 answers

why delegates should be unsafe_unretained and not weak?

I added ARC to an app I'm working on. Unfortunately, it crashes. I found that the automatic script which updates all apps to ARC gave __unsafe_unretained qualifier to all id< protocolName> type. Why isn't it a weak type? I have deployed the app and…
0
votes
2 answers

iOS ARC block retain cycle

Can someone confirm if the block below is turning into a retain cycle please? Please note the block is being called by SampleClass2 not SampleClass1. @interface SampleClass1{ NSArray *_array; } @implementation SampleClass1 -(void) doSomething…
aprofromindia
  • 1,111
  • 1
  • 13
  • 27