sharedInstance
我用下面的代码创建了一个:
+ (MyClass *)sharedStore
{
@synchronized(self)
{
if (sharedInstance == nil)
sharedInstance = [[self alloc] init];
}
return sharedInstance;
}
我有一个功能MyClass
- (MyClass *)initService:(int)serviceType areaSelected :(int)areaID target:(id)delegate
{
self = [super init];
// again init function is called after having a shared instance which is resulting in memory leak.
if(self)
{
jsonParserObject = [[MyClassInfoParser alloc]init];
if(jsonParserObject != nil)
{
serviceTypeRequested = serviceType;
selectedAreaId = areaID;
NSString *url = [self createUrlandBodyForService];
NSLog(@"URL : %@",url);
if ([Reachability connected])
{
if(url.length)
{
BOOL status = [self initRequest:url withDelegate:delegate];
if(status)
NSLog(@"Request for fields successfully");
else
NSLog(@"Failed to send request for fields");
}
else
{
[super responseFailedNotification:nil];
}
}
else
{
[super networkError:delegate];
}
}
}
return self;
}
要调用上述函数,我使用代码
- (void)startServiceForInformation
{
serviceObj = [[MyClass sharedStore]initService:2 areaSelected:self.areaId target:self];
[serviceObj start];
}
这导致内存泄漏导致崩溃。谁能帮我解决这个内存泄漏?