gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: big memory leak in GSString


From: Pirmin Braun
Subject: Re: big memory leak in GSString
Date: Tue, 8 Jan 2013 01:28:00 +0100

I've extended the test to reflect what happens in our App and now the problem 
shows:
Code:
#import <Foundation/Foundation.h>


int
main(int argc, char **argv)
{
    NSString *s = @"fi-rst|sec-ond|thi-rd",*s1;
    NSArray *a,*a1;
    NSAutoreleasePool *pool =[NSAutoreleasePool new];

    a = [s componentsSeparatedByString:@"|"];
    s1 = [a objectAtIndex:0];

    NSLog(([NSString stringWithFormat:@"a %@ has retainCount of %i",s1,[s1 
retainCount]]));

    a1 = [s1 componentsSeparatedByString:@"-"];
    NSLog(([NSString stringWithFormat:@"b %@ has retainCount of %i",s1,[s1 
retainCount]]));

    [[a1 objectAtIndex:0]retain];
    NSLog(([NSString stringWithFormat:@"c %@ has retainCount of %i",s1,[s1 
retainCount]]));

    [s1 retain];
    NSLog(([NSString stringWithFormat:@"after [s1 retain]: %@ has retainCount 
of %i",s1,[s1 retainCount]]));


    [pool release];

    NSLog(([[NSString alloc]initWithFormat:@"after [pool release]: %@ has 
retainCount of %i",s1,[s1 retainCount]]));

    exit (0);
    return 0;
}

WO:
> Running 'TestTool.exe'...
Jan 08 01:16:43 TestTool[3952] a fi-rst has retainCount of 1
Jan 08 01:16:43 TestTool[3952] b fi-rst has retainCount of 1
Jan 08 01:16:43 TestTool[3952] c fi-rst has retainCount of 1
Jan 08 01:16:43 TestTool[3952] after [s1 retain]: fi-rst has retainCount of 2
Jan 08 01:16:43 TestTool[3952] after [pool release]: fi-rst has retainCount of 1
> Finished running 'TestTool.exe'.

GNUStep:
s15351252:/usr/GNUstep/Local/Projects/TestTool# 
/usr/GNUstep/Local/Tools/TestTool
2013-01-08 01:19:55.434 TestTool[25320] a fi-rst has retainCount of 2
2013-01-08 01:19:55.438 TestTool[25320] b fi-rst has retainCount of 4
2013-01-08 01:19:55.438 TestTool[25320] c fi-rst has retainCount of 4
2013-01-08 01:19:55.438 TestTool[25320] after [s1 retain]: fi-rst has 
retainCount of 5
2013-01-08 01:19:55.438 TestTool[25320] after [pool release]: fi-rst has 
retainCount of 2


the substrings of a substring retain their string from which they where 
splitted off;
when those 2nd generation substrings are retained, the 1st generation 
substrings won't get deallocated;
but they should, they are just intermediate objects;

-- 
Pirmin Braun - IntarS Unternehmenssoftware GmbH - Sinziger Str. 29a - 53424 
Remagen
+49 2642 308288 +49 174 9747584 - skype:pirminb www.intars.de  address@hidden 
intars.sourceforge.net
Geschäftsführer: Pirmin Braun, Ralf Engelhardt Registergericht: Amtsgericht 
Coburg HRB3136



reply via email to

[Prev in Thread] Current Thread [Next in Thread]