« first day (1459 days earlier)      last day (1559 days later) » 

6:55 AM
@sathyachinnasamy welcome
 
Hi All I have a doubt in ARC.
what is retain?
I have reffered some tutorila for ARC but I could not understand retain
what does "retaining object" means
?
 
which means retaining the object from memory release
suppose when you are having class called A

class A {
// some functionalities are there
}

var a = A() // creating strong reference. Now retain count is 1
var aa = a // You are creating one more reference for class A by assigning it to some other variable.
now retain count is 2. Until retain count comes to 0 the class A will not get release from memory
so, aa = nil. Now retain count comes to 1
again a = nil. Now retain count comes to 0. Now class A get release from memory
You can do this task using playground then you will get to know
class A: UIViewController {
override func ViewDidLoad() {
super.viewDidLoad()
}
deinit() {
print("Class got released from memory")
}
}
now do var a = A()
var aa = a

now set aa = nil. deinit will not call. again set a = nil. Now deinit message will get print. Which means class got released from memory
even at first you set a = nil will not call deinit message cause variable aa having strong reference with instance of A.
again set aa = nil, will call deinit
 
7:31 AM
@BoominadhaPrakashM Fire answer I got understand it Thanks
I have tried above code in playground
where I am getting this error at below line
a = nil
error message : 'nil' cannot be assigned to type 'A'
and also
on below line I have a doubt
var aa = a // You are creating one more reference for class A by assigning it to some other variable.
here which one's retain count will get increase ?
The Class A .. Am I right?
 
@sathyachinnasamy can you show your code
@sathyachinnasamy yeah right
 
7:54 AM
import UIKit
import PlaygroundSupport
class A: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
deinit {
print("Class got released from memory")
}
}


class B: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var a = A()
var aa = a
a = nil
}
deinit {
print("Class got released from memory")
}
}
 
don't create class B
in playGround, just outside of the class do that
 
I have tried like this
import UIKit
import PlaygroundSupport
class A: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
deinit {
print("Class got released from memory")
}
}


var a = A()
var aa = a
a = nil
getting same error
 
8:11 AM
you will be mastered in ARC
 
 
1 hour later…
9:11 AM
@BoominadhaPrakashM hiii bro
 
@DilipTiwari hi
 
@BoominadhaPrakashM Thank you so much :-
 

« first day (1459 days earlier)      last day (1559 days later) »