# Import
# Import
- (Id) init
{
self = [super init];
[Self usedMemory];
[Self addtitle: @ "d"];
[Self usedMemory];
return self;
}
- (Void) addtitle: (NSString *) title
{
for (double i = 0; i <200000; i + +) {
/ / NSString * T2 = [@ ">" stringByAppendingString: title];
NSObject * T2 = [[NSObject alloc] init];
[T2 release];
}
}
- (Void) usedMemory
{
task_basic_info_data_t taskInfo;
mach_msg_type_number_t infoCount = TASK_BASIC_INFO_COUNT;
kern_return_t kernReturn = task_info (mach_task_self (),
TASK_BASIC_INFO,
(Task_info_t) & taskInfo,
& InfoCount);
if (kernReturn! = KERN_SUCCESS
) {
NSLog (@ "Nofound");
}
NSLog (@ "Memery% f", taskInfo.resident_size / 1024.0 / 1024.0);;
}
The result:
2013-09-14 18:56:24.240 menerytest [5913: c07] Memery16.789062
2013-09-14 18:56:24.281 menerytest [5913: c07] Memery17.128906
If [T2 release]; commented:
2013-09-14 19:05:41.786 menerytest [6476: c07] Memery16.890625
2013-09-14 19:05:41.804 menerytest [6476: c07] Memery20.320312
Originally T2 used is NSString * T2 = [@ ">" stringByAppendingString: title];
Memory does not release a substantial growth, growth release memory after the first result similar to the above, but the program will eventually crash out.
Why release a memory leak or fall out? Although quite small. And why "[@"> "stringByAppendingString: title]" After the release will crash it?
Reply:
stringByAppendingString: title returns the NSString already autorelease, you no longer need to manually release
Reply:
You lost the excessive release
Reply:
Thanks a floor, but I still want to know
NSObject * T2 = [[NSObject alloc] init];
[T2 release];
This tiny memory go between the
Reply:

Reply:
[Self usedMemory];
NSAutoreleasePool * pool = [NSAutoreleasePool new];
.....
[Pool release];
[Self usedMemory];
You try this.
Reply:
Testing is still the same, but also tested with
@ Autoreleasepool {
for (double i = 0; i <200000; i + +)
{
NSObject * T2 = [[NSObject alloc] init];
[T2 release];
}
}
Reply:
I see, I do not speakReply:
You do not need to release NSString above the bar
Reply:
Reply:
You do not care about this, so then you do not divulge it.
No comments:
Post a Comment