Go to bottom

anybody with iphone and/or objective c knowledge: please have a look: NSString constrainedToSize problem

category: general [glöplog]

hello fellow softworkers!

after years of passivly abusing the random image thread, this is my first post (=desperate need of help). any idea would be greatly appreciated! for an iphone project, we use


problem: the function allocates memory that is not released afterwards. with several thousand calls, this eats up a lot of memory. too much memory.


CGSize theSize;
NSString *myString;
UIFont *tmpfont = [UIFont fontWithName:@"Arial" size:20];

for all strings...
myString = [[NSString alloc] initWithString:@"Teststring"];
theSize = [myString sizeWithFont:tmpfont constrainedToSize:CGSizeMake(MAXFLOAT,MAXFLOAT)];
[myString release];

thanks so much!


added on the 2009-03-24 19:31:34 by vmp510 vmp510
try autorelease pool myString = [ [[NSString alloc] initWithString:@"Teststring"] autorelease] so it should be automatically released when it goes out of scope ( when the reference count is 0 )

Hope it helps :)
added on the 2009-03-24 19:50:58 by c0d3rguy c0d3rguy
of course, in this case you won't need the [myString release];
added on the 2009-03-24 19:56:52 by c0d3rguy c0d3rguy
what c0d3rguy said
added on the 2009-03-24 20:17:13 by neoneye neoneye
Texel is that you? :)
added on the 2009-03-24 23:36:04 by kurli kurli
i don't think it is he. but who can be sure these days :)
added on the 2009-03-25 01:41:11 by button button
who would've thought there were two roman corteses in the scene!
added on the 2009-03-25 07:40:54 by skrebbel skrebbel
no, it's not me...
added on the 2009-03-25 09:41:41 by texel texel
Anyway, I believe we are all Roman Cortes, so... thanks for using my avatar :)
added on the 2009-03-25 09:42:46 by texel texel
true, true... we are all ninjas of dma also :)
added on the 2009-03-25 11:09:27 by ninja ninja
thanks for your help. it turned out that the problem only shows up when we use chinese characters. that is a problem...

thanks anyhow, sph
added on the 2009-03-26 11:58:25 by vmp510 vmp510


Go to top