Questions tagged [strong-references]

Strong references are regular references that are protected from garbage collection, in contrast to weak references.

Strong references are regular references that are protected from garbage collection, in contrast to .

86 questions
2
votes
2 answers

Swift class: reference cycle

When I run the below program, it produces segmentation fault. Can you please help me figure out why? Thanks class Animal:NSObject{ var name:String! var age:UInt! weak var spouse:Animal? init(name:String,age:UInt){ …
simplytunde
  • 197
  • 2
  • 7
2
votes
1 answer

How to reference UILabel strong reference programmatically using Swift?

Using Swift, I have a UILabel that was created programmatically in the viewDidLoad override function: var middleDate = UILabel(frame: CGRect(x: (screenWidth / 2) - 45, y: 0, width: 90, height: 20)) middleDate.text = "3:13:46 PM" …
Eric
  • 157
  • 1
  • 11
2
votes
4 answers

Deallocation of weak reference iOS

I'm developing a custom iOS SDK. I'm creating weak, strong references based on my requirement. What is not clear to me is: when will the weakly reference object gets de-allocated? Assume I have 3 objects A,B,C. A has a weak reference to B and B has…
2
votes
2 answers

property_getAttributes() does not make difference between retain, strong, weak and assign properties when set read-only

I'm trying to get the property attributes of an object with the property_getAttributes() runtime function. Some properties are set read-only. But the problem comes when I try to make the difference between retain/strong, weak and assign properties.…
2
votes
2 answers

Strong References (Objective -C)

I'm trying to better understand Strong References, but in the context of a particular example that I will list below. Lets say that I have a global variable called gPrefs. It's of type Preference Class, a custom class I made. I've declared in its…
Joseph Astrahan
  • 8,659
  • 12
  • 83
  • 154
1
vote
1 answer

How to dispose from UIView subviews on one ViewController when navigating away from it

I'm starting to learn Swift and decided to build an app but without storyboard. My SceneDelegate scene function instantiates a TabBarController window = UIWindow(frame: UIScreen.main.bounds) let tb = TabBarController() window?.rootViewController =…
Jorge Guerreiro
  • 682
  • 6
  • 22
1
vote
2 answers

NotifcationCenter causing a strong reference cycle - Swift 5

It appears I am getting a Strong Reference Cycle when using the NotifcationCenter. I am using NotificationCenter to observe the Rotation of the device. (While some would argue this is not the best way to determine the device rotation, this currently…
1
vote
2 answers

Finding cause of strong reference cycle

I have some trouble finding the cause of a View Controller not being released. It only appears at the top of the hierarchy as it is a sub page with the only purpose being to chat(a minor feature) with other users of the app. I have already tried…
Ben Ong
  • 913
  • 1
  • 10
  • 25
1
vote
1 answer

View controller with strong references causing memory leaks

I have an issue with strong references in one of my view controllers which is causing a memory leak. First, my setup: 2 view controllers (v1 and v2). v1 segues to v2, and v2 has a close button that pops itself back to v1. v2 contains code that tries…
Prabhu
  • 12,995
  • 33
  • 127
  • 210
1
vote
0 answers

Unable to find strong reference to an object using instrument - XCode 8

Let's say I have root view controller A. Then I push view controller B. But after pop B, its not getting released (checked using dealloc method, which is not getting called upon popViewController. Please correct me if I'm wrong). I've done lot of…
iAkshay
  • 1,143
  • 1
  • 13
  • 35
1
vote
1 answer

Is this a strong reference cycle or memory leak at all?

The examples about strong reference cycles I usually see involve two classes with properties pointing to each other. However, what if only one of the classes has a property pointing to the other instance like this: class ClassA { var classB:…
TruMan1
  • 33,665
  • 59
  • 184
  • 335
1
vote
2 answers

Does this objective-c code create a strong reference cycle?

I am working in someone else's iOS project. ARC is (and to the best of my knowledge always has been) enabled. The code is littered with button-press handlers that create an instance of some view controller, set its delegate to self, and then show…
1
vote
1 answer

add __strong ivar at runtime under ARC

A normal ivar declared in @interface is __strong default. @interface XLPerson : NSObject { NSString *name; // __strong default } @end Now, I create above class at runtime: Class XLPerson = objc_allocateClassPair([NSObject class], "XLPerson",…
1
vote
1 answer

strong references to views in an activity/fragment and garbage collection

In an activity, I typically keep around strong references to views in order to not need to findViewById(...) each time I have to update said view. In doing so, Activities end up looking like this: SomeActivity extends Activity implements…
ChrisMcJava
  • 2,145
  • 5
  • 25
  • 33
1
vote
1 answer

What holds strong reference onto my viewController?

I am removing viewController from controller hierarchy with removeFromParentViewController, but deinit of view controller not get called. How can I check what holds strong reference on it? Any way to see reference graph exist in memory? This is how…
János
  • 32,867
  • 38
  • 193
  • 353