Getting a level 2 memory level using an overlay with MapKit

I have a problem with memory alerts on iPhone. I delete overlays and insert new ones. This happens every 5 seconds. But after a while, like half a minute, I get a memory warning, and my application crashes.

What can I do, a subview of my overlay is a problem ...
A triangle will be created using "drawRect".
I tested it, without a triangle this is not a problem, and the application works stably.

But only when I add a triangle to the circle.

When the triangle class is empty, the same problem occurs.

- (MKOverlayView *)mapView:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay
{       
    MKOverlayView *overlayReturn = nil;

    if ([overlay isKindOfClass:[MKCircle class]] == YES) {
    MKCircleView *circleView = [[[MKCircleView alloc] initWithOverlay:overlay]autorelease] ; 

    circleView.strokeColor = [UIColor redColor]; 
    circleView.lineWidth = 1;
    circleView.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.4];

   Triangle* triangle = [[Triangle alloc]initWithFrame:CGRectMake(circleView.circle.radius*10-1000, circleView.circle.radius*10-1000, 2000, 2000)];

    triangle.backgroundColor = [UIColor clearColor];
    [circleView addSubview:triangle];
    [triangle release];

    return circleView;
}
+3
source share
3 answers

, , . , - Triangle, .

+1

. , , . , MKCircle, MKPolygon ...

, viewForOverlay . AND.

, . Apple: ...

. .

+1

I'm not sure how you use this method (in a loop or what), but if you want, set up another NSAutoreleasepool to free these objects as soon as you can.

Here is an example of how you could use it with a loop to get rid of auto-implemented ASAP objects.

for (NSInteger i = 0; i < 99999999999999; i++ )
{
    NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];
    NSString *string = [NSString string];
    // code
    [innerPool release];
}
0
source

All Articles