|
|
The memory management functions and its usage are handled in through the Swift language by Automatic reference counting (ARC). ARC is generally used to initialize and deinitialize the given system resources thereby it helps in releasing memory spaces which are used by the class instances when the instances are no longer required. ARC also keeps track of the information about the relationships between our code instances which helps in managing the memory resources effectively.
When we run the above program using playground, we get the following result -
When we run the above program using playground, we get the following result -
Class type properties has two ways to resolve the strong reference cycles -
These references are generally used to enable one instance such that it can refer to other instances in a reference cycle. Then these instances may refer to each and every instances instead of caring about the strong reference cycle. If the user knows that some instance may return 'nil' values we can point that using the weak reference. Whenever the instance is going to return something rather than nil value then declare it by using unowned reference.
When we run the above program using playground, we get the following result -
When we run the above program using playground, we get the following result -
Whenever we assign a closure to the class instance property and to the body of the closure to capture a particular instance then a strong reference cycle can occur. Strong reference to the closure can be defined by 'self.someProperty' or 'self.someMethod()'. Strong reference cycles are used as reference types for the closures.
When we run the above program using playground, we get the following result -
When the closure and the instance are used to refer to each other then the user may define the capture in a closure as an unowned reference. Then it would not allow the user to deallocate the instance at the same time. If the instance sometimes returns a 'nil' value define the closure using the weak instance.
When we run the above program using playground, we get the following result -
|
|
Swift Programming Related Practice Tests |
|
---|---|
Core Java Practice Tests | UNIX/XENIX Practice Tests |
Basic Programming Practice Tests | Global Money Markets Practice Tests |
IOS Practice Tests | JSON (JavaScript Object Notation) Practice Tests |
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.