The mission I am engaged on is a mixture of Swift and Goal-C. This is the snippet:
// ViewController.m
@interface ViewController ()
@property (nonatomic, sturdy) MyModel *mannequin;
@finish
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.mannequin = [[MyModel alloc] initWithIntValue:10];
}
// MyModel.swift
fileprivate class SomeProperty {
init() {
print("SomeProperty init")
}
}
class MyModel: BaseModel {
non-public let property = SomeProperty()
}
// BaseModel.h
@interface BaseModel : NSObject
- (instancetype)initWithIntValue:(int)intValue;
- (instancetype)initWithIntValue:(int)intValue doubleValue:(double)doubleValue;
@finish
// BaseModel.m
@implementation BaseModel
- (instancetype)initWithIntValue:(int)intValue doubleValue:(double)doubleValue {
if (self = [super init]) {
}
return self;
}
- (instancetype)initWithIntValue:(int)intValue {
return [self initWithIntValue:intValue doubleValue:0];
}
@finish
Apparently, I discover when MyModel occasion is initialized, SomeProperty init shall be printed twice, which suggests two SomeProperty situations are created. What’s worse, Debug Reminiscence Graph reveals that there’s a SomeProperty object reminiscence leak. So why is that this and the way can I repair it?