Leaking UIView
When run in Activity Monitor, the actual memory usage for a program executing the following piece of code will increase infinitely:
CGRect frame = CGRectMake(0,0,0,0);
while(true)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
UIView *test = [[UIView alloc] initWithFrame:frame];
[test release];
[pool release];
}
It happens that all objects obtained from UIView will flow. Some of them will flow more than others (UITextView in particular has drawn attention to this issue). Leaks are not detected on the leak monitor - their presence is only detected when memory usage is constantly increasing, which ultimately leads to the fact that the application is interrupted by the OS due to memory exhaustion.
Has anyone noticed this before? For the record, the code was compiled for OS 3.0.
source to share
I think this is a tool issue . The tools don't work correctly when used with iPhone OS 3.0, for example, you can't see the stack trace. When using 3.1 in the simulator, this problem disappears (see images). The fact that they don't show up as leaks in the tools contributes to my guess.
Of course, it could also be an issue with iPhone OS 3.0, which was fixed in iPhone OS 3.1.
(source: hillrippers.ch )
^^ Tools with OS 3.0
(source: hillrippers.ch )
^^ Tools with OS 3.1
This code is used (in applicationDidFinishLaunching:
NSUInteger i = 0;
CGRect frame = CGRectMake(0.f, 0.f, 100.f, 50.f);
while (i < 100000) {
UIView *test = [[UIView alloc] initWithFrame:frame];
[test release];
i++;
}
source to share
I agree that this is most likely a bug in the iPhoneOS. It looks like it is CALayer
not being released. If you force an additional CALayer release ( [test.layer release]
which is crazy, but "works"), you will dramatically reduce memory usage, but you will find that QuartCore still leaks at least 16 bytes per iteration, which quickly adds up to your stress case. I would open up the radar (bugreporter.apple.com).
source to share