मैं कोको/उद्देश्य-सी के लिए नया हूं और मैं अपनी वस्तुओं के रिलीज के साथ struggeling हूँ।किसी ऑब्जेक्ट को फोरीन लूप में कैसे रिलीज़ करें?
gastroCategoryList = [[NSMutableArray alloc] init];
for (NSDictionary *gastrocategory in gastrocategories) {
NSString *oid = [gastrocategory objectForKey:@"id"];
GastroCategory *gc = [[GastroCategory alloc] initWithId:[oid intValue] name:[gastrocategory objectForKey:@"name"]];
[gastroCategoryList addObject:gc];
}
विश्लेषक मुझे पता चलता है कि "gastrocategory के लिए" के रूप में परिभाषित एक संभावित स्मृति रिसाव है: मैं निम्नलिखित कोड है। लेकिन मुझे यकीन नहीं है कि क्या मैं इसे लूप के अंत में रिलीज़ कर सकता हूं?
निम्नलिखित कोड पर भी:
- (NSArray *)eventsForStage:(int)stageId {
NSMutableArray *result = [[NSMutableArray alloc] init];
for (Event *e in eventList) {
if ([e stageId] == stageId) {
[result addObject:e];
}
}
return result;
}
विश्लेषक मुझसे कहता है कि मेरी "परिणाम" एक संभावित रिसाव है। लेकिन मुझे इसे कहां छोड़ देना चाहिए?
क्या मुझे याद रखने के लिए एक सरल नियम भी है जब मुझे @property पर असाइन, कॉपी, बनाए रखने आदि का उपयोग करना चाहिए?
एक और समस्या:
- (IBAction)showHungryView:(id)sender {
GastroCategoriesView *gastroCategoriesView = [[GastroCategoriesView alloc] initWithNibName:@"GastroCategoriesView" bundle:nil];
[gastroCategoriesView setDataManager:dataManager];
UIView *currentView = [self view];
UIView *window = [currentView superview];
UIView *gastroView = [gastroCategoriesView view];
[window addSubview:gastroView];
CGRect pageFrame = currentView.frame;
CGFloat pageWidth = pageFrame.size.width;
gastroView.frame = CGRectOffset(pageFrame,pageWidth,0);
[UIView beginAnimations:nil context:NULL];
currentView.frame = CGRectOffset(pageFrame,-pageWidth,0);
gastroView.frame = pageFrame;
[UIView commitAnimations];
//[gastroCategoriesView release];
}
मैं समझ नहीं है, "gastroCategoriesView" एक संभावित रिसाव है। मैंने इसे अंत में या ऑटोरेलीज़ के साथ रिलीज़ करने की कोशिश की लेकिन न तो ठीक काम करता है। हर बार जब मैं अपना ऐप समाप्त कर रहा हूं तो विधि को कॉल करता हूं। आपको पुन: बहुत धन्यवाद!
आपको बहुत बहुत धन्यवाद। क्या आप @property समस्या के लिए एक नियम भी जानते हैं? – n3on
@ n3on: अगर किसी संपत्ति को 'रखरखाव' या 'प्रतिलिपि' घोषित किया जाता है, तो आपको अपनी कक्षा की 'डेलोक' विधि में अपना ivar जारी करना चाहिए। – BoltClock
@ बोल्टक्लॉक: ठीक है धन्यवाद। लेकिन मुझे प्रतिलिपि का उपयोग कब करना चाहिए, बनाए रखना चाहिए या असाइन करना चाहिए? – n3on