我想确保我在这里正确理解内存管理.有没有什么特别的理由在这里使用其中一个assignCurrentDate方法?而且,所有这些都导致没有内存泄漏,对吗?
在.h我们有:
NSDate *currentDate1;
NSDate *currentDate2;
NSDate *currentDate3;
NSDate *currentDate3;
//and
@property (nonatomic, retain) NSDate *currentDate1;
@property (nonatomic, retain) NSDate *currentDate2;
@property (nonatomic, retain) NSDate *currentDate3;
@property (nonatomic, retain) NSDate *currentDate4;
Run Code Online (Sandbox Code Playgroud)
在他们中:
-(void) assignCurrentDate1
{
currentDate1 = [[NSDate date]retain];
//[NSDate date] is autoreleased
}
-(void) assignCurrentDate2
{
currentDate2 = [[NSDate date]copy];
}
-(void) assignCurrentDate3
{
self.currentDate3 = [NSDate date];
}
-(void) assignCurrentDate4
{
currentDate4 = [[NSDate alloc]init];
//[[NSDate alloc]init] is not autoreleased.
}
-(IBAction) printDate
{
NSLog ("%@", currentDate1);
NSLog …Run Code Online (Sandbox Code Playgroud) 有没有人知道Java Frames和JFrames的合理性默认设置为不可见?
即你必须调用myFrameObject.setVisible(true)或最终得到一个不可见的应用程序接口.
这一直困扰着我,因为你没有在C#或Objective-C等其他语言中看到这一点.我想知道它是否打算节省时间,或者Java架构师是否只是度过了糟糕的一天.
知道这一点将有助于我理解生命,宇宙和一切的最终答案.