简体   繁体   中英

Swift Memory management in the class

I have a case when I do not understand if A object will be released or not.This is connected with function func b of class A that take as parameter function.

This is simple representation of the problem:

class A {

    func a() {

    }

    func b(_: ()->()) {

    }

    func doThm() {
        b(a)
    }
}



var a = A()
a.doThm()

As your class A has no stored properties there can be no retain cycle.

Calling a function (closure) does not create retain cycles. Storing the closure might.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM