Skip to content

Files

Latest commit

 

History

History
74 lines (46 loc) · 1.09 KB

required_deinit.md

File metadata and controls

74 lines (46 loc) · 1.09 KB

Pattern: Missing deinit method

Issue: -

Description

Ensures that all classes have a deinit method. The purpose of this is to make memory leak debugging easier so all classes have a place to set a breakpoint to track deallocation.

Examples of correct code:

class Apple {
    deinit { }
}


enum Banana { }


protocol Cherry { }


struct Damson { }


class Outer {
    deinit { print("Deinit Outer") }
    class Inner {
        deinit { print("Deinit Inner") }
    }
}

Examples of incorrect code:

class Apple { }


class Banana: NSObject, Equatable { }


class Cherry {
    // deinit { }
}


class Damson {
    func deinitialize() { }
}


class Outer {
    func hello() -> String { return "outer" }
    deinit { }class Inner {
        func hello() -> String { return "inner" }
    }
}


class Outer {
    func hello() -> String { return "outer" }
    class Inner {
        func hello() -> String { return "inner" }
        deinit { }
    }
}

Further Reading