2010-11-25 11 views
1

points Instruments à cette ligne en disant qu'il ya une fuite icifuite avec tableau Mutable même lorsqu'il est libéré

- (void) loadFavoriteData { 
    TradePortMobileAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 

    NSManagedObjectContext *context = [delegate managedObjectContext]; 

    NSManagedObjectModel *objectModel = [[context persistentStoreCoordinator] managedObjectModel]; 

    Session *session = delegate.session; 

    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys: [session objectForKey:@"CTY_CODE"], pCOUNTRY, nil]; 

    NSFetchRequest *fetchRequest = [objectModel fetchRequestFromTemplateWithName:@"fetchAllFavorites" substitutionVariables:param]; 

    [fetchRequest setSortDescriptors: self.dataSorter]; 
    NSError *error; 

    //THIS IS THE LINE INSTRUMENT SAYS THERE IS A LEAK!!!!! 
    NSMutableArray *favorites = [[context executeFetchRequest:fetchRequest error:&error] mutableCopy]; 


    if ([favorites count] > 0) { 

     [self.favoriteList removeAllObjects]; 


     for (NSInteger i=0; i < [favorites count]; i++) { 
      FavoriteData *favorite = [favorites objectAtIndex: i]; 

      if (i < vMaxRecordsInCoreData) { 

       [self.favoriteList addObject:[FavoriteInfo favoriteInfoWithClientId:favorite.clientId    withName:favorite.name 
       withAddress:favorite.address 
       withPhone:favorite.phone 

    withEmail:favorite.email 

    withCountry:favorite.country 

    withLtpId:favorite.ltpId 
       withUpdateTimestamp:favorite.updateTimestamp 
       withNoOfDetails:favorite.noOfDetails]]; 

    } 

    else { 

    [context deleteObject:favorite]; 

    } 

     } 

     if (![context save:&error]) { 
      NSLog(@"deleting excess favorites failed."); 
     } 
     self.navigationItem.leftBarButtonItem.enabled = YES; 

    } 
    else { 
     [self.favoriteList removeAllObjects]; 
     self.navigationItem.leftBarButtonItem.enabled = NO; 
    } 

    [favorites removeAllObjects]; 
    [favorites release]; 

} 

Ceci est la pile

0 CoreFoundation _CFRuntimeCreateInstance 
    1 CoreFoundation __CFStringCreateImmutableFunnel3 
    2 CoreFoundation CFStringCreateWithCString 
    3 CoreData -[NSSQLCore _prepareResultsFromResultSet:usingFetchPlan:withMatchingRows:] 
    4 CoreData -[NSSQLCore _newRowsForFetchPlan:selectedBy:withArgument:] 
    5 CoreData -[NSSQLCore newRowsForFetchPlan:] 
    6 CoreData -[NSSQLCore objectsForFetchRequest:inContext:] 
    7 CoreData -[NSSQLCore executeRequest:withContext:error:] 
    8 CoreData -[NSPersistentStoreCoordinator executeRequest:withContext:error:] 
    9 CoreData -[NSManagedObjectContext executeFetchRequest:error:] 
    MY CODE HERE--->10 TradePortMobile -[FavoritesTableViewController loadFavoriteData] /Users/aldrich/Projects/iPhone/Classes/FavoritesTableViewController.m:281 
    11 TradePortMobile -[FavoritesTableViewController viewWillAppear:] /Users/aldrich/Projects/iPhone/Classes/FavoritesTableViewController.m:54 
    12 UIKit -[UINavigationController viewWillAppear:] 
    13 UIKit -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] 
    14 UIKit -[UITabBarController transitionFromViewController:toViewController:] 
    15 UIKit -[UITabBarController _setSelectedViewController:] 
    16 UIKit -[UITabBarController _tabBarItemClicked:] 
    17 UIKit -[UIApplication sendAction:to:from:forEvent:] 
    18 UIKit -[UITabBar _sendAction:withEvent:] 
    19 UIKit -[UIApplication sendAction:to:from:forEvent:] 
    20 UIKit -[UIControl sendAction:to:forEvent:] 
    21 UIKit -[UIControl(Internal) _sendActionsForEvents:withEvent:] 
    22 UIKit -[UIControl sendActionsForControlEvents:] 
    23 UIKit -[UIApplication sendAction:to:from:forEvent:] 
    24 UIKit -[UIControl sendAction:to:forEvent:] 
    25 UIKit -[UIControl(Internal) _sendActionsForEvents:withEvent:] 
    26 UIKit -[UIControl touchesEnded:withEvent:] 
    27 UIKit -[UIWindow _sendTouchesForEvent:] 
    28 UIKit -[UIApplication sendEvent:] 
    29 UIKit _UIApplicationHandleEvent 
    30 GraphicsServices PurpleEventCallback 
    31 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ 
    32 CoreFoundation __CFRunLoopDoSource1 
    33 CoreFoundation __CFRunLoopRun 
    34 CoreFoundation CFRunLoopRunSpecific 
    35 CoreFoundation CFRunLoopRunInMode 
    36 GraphicsServices GSEventRunModal 
    37 GraphicsServices GSEventRun 
    38 UIKit UIApplicationMain 
    39 TradePortMobile main /Users/aldrich/Projects/iPhone/main.m:14 
    40 TradePortMobile start 

de quelqu'un me donne un coup de pouce à la bonne direction? ou une réponse à cette fuite je ne peux pas résoudre :)

Répondre

1

L'outil de fuite peut seulement pointer vers l'endroit où la mémoire a été allouée, la fuite se produit probablement comme vous passez certaines des propriétés de chaque objet de la matrice dans le code suivant:

[self.favoriteList addObject:[FavoriteInfo favoriteInfoWithClientId:favorite.clientId    withName:favorite.name 
       withAddress:favorite.address 
       withPhone:favorite.phone 

    withEmail:favorite.email 

    withCountry:favorite.country 

    withLtpId:favorite.ltpId 
       withUpdateTimestamp:favorite.updateTimestamp 
       withNoOfDetails:favorite.noOfDetails]]; 

vous devez vérifier ce qui se passe avec les paramètres de favoriteInfoWithClientId: favoris - si vous conservez l'un de ces alors vous aurez une fuite ...

espérons que cette aide

+0

Merci je vais regarder dans – Aldrich

+0

il y a un removeAllObjects et une version pour favoriteList dans dealloc. Est-ce que ça devrait le couvrir? comment puis-je faire le contenu de favoriteList ne pas être une fuite? – Aldrich

+0

removeAllObjects sur favoriteList "devrait" couvrir, mais dépendrait d'un certain nombre de choses! Par exemple, si la classe FavoriteInfo ne nettoie pas dans son dealloc, vous aurez une fuite. –