The following code creates a scrollview and adds it to my main view. It also creates a UIImageView inside the ScrollView and also adds a tiny little image to the mainview in its own UIImageView. The class ScrollView is just UIScrollView but it also implements touch events. (My problem happens if I use the base class UIScrollView so I know that isn't the issue). The UIScrollView contains a custom image that I create at run-time from a bitmap context.
What's happening is this view will show up (it's just a white scrollable box within my view). And the three "removeFromSuperView's" at the end will remove them, as it should. The problem is, if I repeat this 12-18 times, the application will crash! I've been fighting this for over a day. Does anyone have any ideas? The code is for iOS 3.2 on an original iPad.
I *DID* notice that if I replace the [imview setImage:uimg] with a static image, the crashing never occurs. I can do this 200 times and never encounter a crash. That is, replacing it with [imview setImage:[UIImage imageNamed:@"blahblah.png"
]]; will stop the crashing. But, I need to be synthesizing the image at run-time for obvious reasons.
Any ideas? :)
msview = [[ScrollView alloc] initWithFrame:CGRectMake(Mx, My, Mwid, Mhgt)];
msview.backgroundColor = [UIColor grayColor];
closex = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"someimage.png"]];
[myview addSubview:closex]; closex.frame = CGRectMake(Mx+Mwid-15, My-15, 30, 30);
for(int i=0;i<(tot>>2);i++) gbuff[i]=0xfff0f0f0;
colorSpace = CGColorSpaceCreateDeviceRGB();
int bytewid = Mwid; bytewid*=4;
CGContextRef bmCtx = CGBitmapContextCreate(gbuff, Mwid, TOThgt, 8, bytewid, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGImageRef image = CGBitmapContextCreateImage(bmCtx);
CFRelease(bmCtx); free(gbuff); CGColorSpaceRelease(colorSpace);
UIImage *uimg = [UIImage imageWithCGImage:image]; CGImageRelease(image);
imview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, Mwid,TOThgt)];
[msview setContentSize:CGSizeMake(Mwid, TOThgt)];