2013-10-20 8 views
6

के कारण समाप्त कैसे किया जा सकता है मैं अपनी बड़ी परियोजना में MKMapView का उपयोग कर रहा हूं। जब मैं बहुत एनोटेशन (700 से अधिक) लोड करता हूं और मैपकिट पर उन बिंदुओं के बीच रेखा खींचता हूं, तो मुझे एक्सकोड त्रुटि संदेश मिल रहा है "स्मृति त्रुटि के कारण समाप्त" और ऐप क्रैश हो रहा है। आप छवि पर देख सकते हैं:मेमोरी त्रुटि

enter image description here

मैं इस तरह लाइन द्वारा जोड़ा जा रहा:

enter image description here

अगर मैं कम से कम 700 एनोटेशन है, यह बहुत अच्छी तरह से काम कर रहा है। मुझे लगता है कि इसमें कुछ स्मृति समस्या है। मैं इस समस्या को कैसे हल कर सकता हूं? कोई सलाह।

// adding annodation 
    for (int i=0; i<[fetcher.locations count]; i++)//fetcher.locations is NSMutableArray and inside have locationInfoClass objects . locationInfoClass is hold CLLocationCoordinate2D. 
     { 
      locationInfoClass * loc=[fetcher2.locations objectAtIndex:i]; 

      CLLocationCoordinate2D coordinate1; 
      coordinate1.latitude = loc.lat; 
      coordinate1.longitude = loc.lon; 

      myAnnotation * ann = [[myAnnotation alloc] initWithCoordinate:annCoordinate   title:@"uniqtitle" subtitle:@"uniqsubtitle"]; 
      [mapView addAnnotation:ann]; 


     } 
     #pragma mark - 
     #pragma mark -mapview overlay 


     CLLocationCoordinate2D *coordinates 
     = malloc(sizeof(CLLocationCoordinate2D) * [mapView.annotations count]); 

     for (int i=0; i<[mapView.annotations count]; i++) { 
      myAnnotation * ann=[mapView.annotations objectAtIndex:i]; 
      coordinates[i]=ann.coordinate; 


     } 


     self.routeLine = [MKPolyline polylineWithCoordinates:coordinates count:mapView.annotations.count]; // pinlerin sayısı ne kadarsa o kadar çizgi çiziyor. 
     free(coordinates); 
     [self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      [self.mapView addOverlay:self.routeLine]; 
     }); 

ज फ़ाइल

@property (nonatomic, retain) MKPolyline *routeLine; //your line 
@property (nonatomic, retain) MKPolylineView *routeLineView; //overlay view 

MKMapView प्रतिनिधि के तरीके की है।

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay 
{ 
    if(overlay == self.routeLine) 
    { 
     if(nil == self.routeLineView) 
     { 
      self.routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine]; 
      self.routeLineView.fillColor = [UIColor redColor]; 
      self.routeLineView.strokeColor = [UIColor redColor]; 
      self.routeLineView.lineWidth = 3; 

     } 

     return self.routeLineView; 
    } 

    return nil; 
} 
/* 
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views 
{ 
    MKAnnotationView *annotationView = [views objectAtIndex:0]; 
    id <MKAnnotation> mp = [annotationView annotation]; 
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500); 
    [mv setRegion:region animated:YES]; 

}*/ 
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 

    MKAnnotationView *pinView = nil; 
    if(annotation != mapView.userLocation) 
    { 
     static NSString *defaultPinID = @"ftffggf"; 
     pinView = (MKAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
     if (pinView == nil) 
      pinView = [[MKAnnotationView alloc] 
         initWithAnnotation:annotation reuseIdentifier:defaultPinID]; 

     //pinView.pinColor = MKPinAnnotationColorGreen; 
     pinView.canShowCallout = YES; 



     //pinView.animatesDrop = YES; 
     UIImage * image=[UIImage imageNamed:@"pin.png"]; 
     CGSize size=CGSizeMake(50, 63);//set the width and height 
     pinView.image = image 
    } 
    else { 
     [self.mapView.userLocation setTitle:@"I am here"]; 
    } 
    pinView.centerOffset = CGPointMake(0,-23); 
    return pinView; 

} 
+0

यह पूरा संदेश है? कोई बैकट्रैक या अपवाद नहीं है? – nielsbot

+0

हाँ संदेश केवल यही है। ऐप एनोटेशन जोड़ने और ओवरले जोड़ने के लिए 30 सेकंड इंतजार कर रहा है। अचानक यह संदेश दिखा रहा है। –

+0

अपने ऐप को इंस्ट्रूमेंट्स के तहत चलाएं और मेमोरी ग्रोथ देखें। यदि यह आपके अन्य प्रश्न के समान ऐप है जहां आपके पास 90 से अधिक धागे हैं, तो यह आसानी से समस्या हो सकती है। – bbum

उत्तर

5

हाल ही में - और बढ़ती आवृत्ति के साथ - मैं वही त्रुटि दिखाई दे दिया है हर बार जब मैं XCode से एक परियोजना भाग गया, क्रम के बाद लगभग ठीक एक मिनट, भले ही ("मेमोरी त्रुटि के कारण समाप्त") मैं शुरू होने के बाद ऐप को स्पर्श नहीं करता हूं।

मैं था नहीं देखने:

  • जब प्रोफाइलर के साथ चलाने के किसी भी आश्चर्य की बात स्मृति की खपत।
  • ऐप को समाप्त होने पर होने वाले किसी भी स्पष्ट पैटर्न (यह होने की अवधि के अलावा, लेकिन इसमें कुछ समय लग गया)।
  • कोई भी "बिना अपवाद के कारण समाप्त करने वाला ऐप" त्रुटि संदेश, या कंसोल में स्टैक निशान।
  • किसी भी अपवाद को फेंक दिया जा रहा है (अपवाद ब्रेकपॉइंट; अपवाद: सभी; ब्रेक: फेंक पर)।
  • कोई भी ज़ोंबी ऑब्जेक्ट्स। कोई बेतरतीब ढंग से करता है, तो मैं डिवाइस सीधे बाद यह समाप्त किया गया से ऐप्लिकेशन को फिर से भाग गया स्प्रिंगबोर्ड में वापस कूद -

इसके अलावा, मैं केवल एप्लिकेशन देखा अप्रत्याशित रूप से मौजूद है कि एप्लिकेशन को डिबग में चलाया जा रहा है है।

मैं इन सभी विनिर्देशों का विवरण देने और पृथ्वी पर कैसे समस्या को हल कर सकता हूं, इस बारे में एक समान प्रश्न पूछने वाला था।

तब मेरे पास एक ओह पल था, और कंसोल में दो स्मृति चेतावनियों को देखा, भले ही प्रोफाइलर ने कोई स्मृति समस्या नहीं दिखाई।

लाश। जब मैंने ज़ोंबी ऑब्जेक्ट्स को बंद कर दिया, तो स्मृति चेतावनियां गायब हो गईं, और ऐप अब स्वचालित रूप से समाप्त नहीं हुआ।

संपादित करें:

10 महीने बाद, मैं एक स्थिति है जहाँ यह भी हो सकता है पाया।बाहर निकला, एक अनंत while पाश यह भी कर सकता है:

while (result==nil) { 
    result = [collectionView indexPathForItemAtPoint:testPoint]; 
    testPoint = nextTestPoint(); // After about 12 seconds, at which point this is several tens of thousands of pixels off the edge of the screen, the app dies from "Memory error" 
} 
संबंधित मुद्दे