[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: big memory leak in GSString
From: |
Chan Maxthon |
Subject: |
Re: big memory leak in GSString |
Date: |
Tue, 08 Jan 2013 23:45:07 +0800 |
Why wouldn't you guys just use libobjc2 and ARC?
发自我的 iPad
在 2013-1-8,23:42,Richard Frith-Macdonald <address@hidden> 写道:
>
> On 8 Jan 2013, at 15:35, Pirmin Braun wrote:
>
>> Am Tue, 8 Jan 2013 14:51:07 +0000
>> schrieb David Chisnall <address@hidden> :
>>
>>> On 8 Jan 2013, at 14:41, Pirmin Braun wrote:
>>>
>>>> NSString *s1 = [[a oai:i]copy];
>>>
>>> For an immutable string, -copy just calls retain. If you want to actually
>>> copy the string, do something like:
>>>
>>> NSString *s1 = [NSString stringWithUTF8String: [old UTF8String]];
>>>
>>> (for better performance, you might want to use getCharacters:range: and a
>>> temporary buffer, so that the old string doesn't have to create a new
>>> autoreleased buffer).
>>>
>>> David
>>>
>>> -- Sent from my STANTEC-ZEBRA
>>
>> ok, changed it like this:
>> NSArray *a = [self componentsSeparatedByString:s];
>> NSMutableArray *ma = [NSMutableArray arrayWithCapacity:[a count]];
>> int i,j;
>>
>> // deep copy of a
>> for(i=0,j=[a count];i<j;i++){
>> [ma addObject:[NSString stringWithUTF8String:[[a oai:i]UTF8String]]];
>> }
>> return [NSArray arrayWithArray:ma]; // immutable
>>
>> but also no difference; I give up. For the moment.
>
> You need to wrap things in an autorelease pool so that you can release the
> array by releasing the pool ...
>
> 1. create pool
> 2. call -componentsSeparatedByString:
> 3. make deep copy of resulting array
> 4. release pool
> 5. autorelease and return the copied array
> _______________________________________________
> Gnustep-dev mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/gnustep-dev
- Re: big memory leak in GSString, (continued)
- Re: big memory leak in GSString, Pirmin Braun, 2013/01/07
- Re: big memory leak in GSString, Tom Davie, 2013/01/07
- Re: big memory leak in GSString, Pirmin Braun, 2013/01/07
- Re: big memory leak in GSString, Pirmin Braun, 2013/01/07
- Re: big memory leak in GSString, David Chisnall, 2013/01/08
- Re: big memory leak in GSString, Fred Kiefer, 2013/01/08
- Re: big memory leak in GSString, Pirmin Braun, 2013/01/08
- Re: big memory leak in GSString, David Chisnall, 2013/01/08
- Re: big memory leak in GSString, Pirmin Braun, 2013/01/08
- Re: big memory leak in GSString, Richard Frith-Macdonald, 2013/01/08
- Re: big memory leak in GSString,
Chan Maxthon <=
- Re: big memory leak in GSString, Richard Frith-Macdonald, 2013/01/08
- Re: big memory leak in GSString, Fred Kiefer, 2013/01/13
- Re: big memory leak in GSString, David Chisnall, 2013/01/13
- Re: big memory leak in GSString, Fred Kiefer, 2013/01/13
- Partially solved: big memory leak in GSString, Pirmin Braun, 2013/01/14
- Re: Solved: big memory leak in GSString, Pirmin Braun, 2013/01/14
- Re: big memory leak in GSString, Richard Frith-Macdonald, 2013/01/08