我有一个 SKShapeNode,我将形状设置为 RoundedRectangle,但是当我分析代码时,我收到一条警告,指出对象可能存在泄漏。
我的界面文件如下:
#import <SpriteKit/SpriteKit.h>
@interface letterSpace : SKShapeNode
-(instancetype) initWithCharacter:(NSString *)character xPosition:(float)x yPosition:(float)y device:(NSString *)device;
@property(nonatomic, assign) BOOL occupied;
@property(nonatomic, assign) BOOL whiteSpace;
@property(nonatomic, retain) NSString *character;
@property (atomic) float secondLineX;
@property (atomic) float secondLineY;
@end
然后实现是
#import "letterSpace.h"
@implementation letterSpace
-(instancetype) initWithCharacter:(NSString *)character xPosition:(float)x yPosition:(float)y device:(NSString *)device{
self = [super init];
if(self){
if ([device isEqualToString:@"IPHONE"]) {
[self setPath:CGPathCreateWithRoundedRect(CGRectMake(0, 0, 30, 2), 1, 1, nil)]; // Potential Leak of an object on this line
_secondLineX = 36*8;
_secondLineY = -36;
}else{
[self setPath:CGPathCreateWithRoundedRect(CGRectMake(0, 0, 60, 3.5), 1, 1, nil)]; // Potential Leak of an object on this line
_secondLineX = 575;
_secondLineY = -71;
}
self.strokeColor = [UIColor clearColor];
if ([character isEqual: @" "]) {
self.occupied = TRUE;
self.fillColor = [UIColor clearColor];
self.character = character;
self.whiteSpace = TRUE;
}else{
self.whiteSpace = FALSE;
self.occupied = FALSE;
self.fillColor = [UIColor colorWithRed:80.0f/255.0f
green:227.0f/255.0f
blue:194.0f/255.0f
alpha:1];
}
if (y <8) {
self.position = CGPointMake(x, 0);
}
else{
self.position = CGPointMake(x - _secondLineX, _secondLineY);
}
self.name = character;
}
return self;
}
@end
任何想法如何解决这个泄漏?或者是什么原因造成的?