Skip to content

[SR-8026] ObjC convenience initializers leak stored properties #50559

@dmcyk

Description

@dmcyk
Previous ID SR-8026
Radar None
Original Reporter @dmcyk
Type Bug
Status Resolved
Resolution Invalid

Attachment: Download

Environment

Xcode 10.0 beta (10L176w)
macOS 10.14 Beta (18A293u)
Swift 4.2

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: bbb8f81c61679f46fa506d5e6bd59bae

Issue Description:

Given Objective-C class with following initializers:

-(id _Nonnull)initWithValue:(NSString* _Nonnull)value;
-(id _Nonnull)initConvenienceWithValue:(NSString* _Nonnull)value;

Where `initConvenienceWithValue:` calls to the designated initializer `initWithValue:`.

When such class is subclassed in Swift, both initializers must be overridden. e.g.

class Child: LeakObject {

    let context: Context = {
        return Context()
    }()

    override init(convenienceWithValue value: String) {
        super.init(convenienceWithValue: value)
    }

    override init(value: String) {
        super.init(value: value)
    }
}

When the convenience initializer is called from Swift, there will be one leaked instance of `Context` object, as it will be allocated twice during Swift 'convenience' initializer call and later when Objective-C calls to its designated initializer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions