mercredi 29 octobre 2014

Memory Pressure Issue in read Metadata and remove duplicate


Vote count:

0






  • (void) objectParsed_ListAllMedia:(NSDictionary *)dictionary {


    @try {



    self.viewLoading.hidden=1;

    [self.arrGaalleryMediaName removeAllObjects];
    [self.arrMediaNames removeAllObjects];


    if(self.arrOnlyServerImages == nil){
    self.arrOnlyServerImages = [[NSMutableArray alloc] init];
    }

    if([self.arrOnlyServerImages count] >0){
    [self.arrOnlyServerImages removeAllObjects];
    }


    if (dictionary==nil) {

    [self.gridCollectionView reloadData];
    return;
    }
    // Filter Array for Audio file

    NSPredicate *predicate = [NSPredicate predicateWithFormat: @"type != 'audio' "];
    self.arrOnlyServerImages = [NSMutableArray arrayWithArray:[[dictionary objectForKey:@"objects"] filteredArrayUsingPredicate:predicate]];

    [self.gridCollectionView reloadData];
    return;

    // Remove duplicate Start //Read Meta Data and Duplicate from Download, Duplicate from upload START

    dispatch_queue_t backgroundQueue = dispatch_queue_create("com.memreas.myqueue", 0);

    dispatch_async(backgroundQueue, ^{

    NSMutableArray *arr = [NSMutableArray array];
    NSMutableIndexSet * indexSet = [NSMutableIndexSet indexSet];

    for (int i=0; self.assetAry.count>i; i++) {

    ALAsset *result =self.assetAry[i];
    ALAssetRepresentation *imageRep = [result defaultRepresentation];
    NSDictionary * customMetaDic = [imageRep metadata][(NSString*)kCGImagePropertyIPTCDictionary];

    if (customMetaDic) {

    [self.arrMediaNames addObject:customMetaDic[(NSString*)kCGImagePropertyIPTCObjectName]?customMetaDic[(NSString*)kCGImagePropertyIPTCObjectName]:@""];
    }else{
    [self.arrMediaNames addObject:@""];
    }

    [self.arrGaalleryMediaName addObject:[self getFileNameWithExtensionFromPath:imageRep.url]];

    }


    for (int i=0; self.arrOnlyServerImages.count>i; i++) {

    NSMutableDictionary* obj = self.arrOnlyServerImages[i];
    NSMutableDictionary * dic2 = [NSMutableDictionary dictionaryWithDictionary:obj];
    BOOL isArrMedia =[self.arrMediaNames containsObject:dic2[@"media_name"]];
    BOOL isGallery =[self.arrGaalleryMediaName containsObject:dic2[@"media_name"]];

    if (isArrMedia||isGallery) {

    dic2[@"isDownloaded"] = [NSNumber numberWithBool:YES];
    [indexSet addIndex: isArrMedia?[self.arrMediaNames indexOfObject:dic2[@"media_name"]] :[self.arrGaalleryMediaName indexOfObject:dic2[@"media_name"]]];

    }else{

    dic2[@"isDownloaded"] = [NSNumber numberWithBool:NO];
    }

    [arr addObject:dic2];

    }

    dispatch_async(dispatch_get_main_queue(), ^{

    @try {

    self.arrOnlyServerImages = arr;
    [self.assetAry removeObjectsAtIndexes:indexSet];
    [self.gridCollectionView reloadData];

    }
    @catch (NSException *exception) {
    NSLog(@"%@",exception);
    [self.gridCollectionView reloadData];
    }

    });


    });

    // Remove duplicate END //Read Meta Data and Duplicate from Download, Duplicate from upload END

    [self.gridCollectionView reloadData];
    [self.gridView.collectionView reloadData];
    [self.location performSelector:@selector(stopActivity) withObject:nil afterDelay:2];


    } @catch (NSException *exception) { NSLog(@"%@",exception); }




}


I have issue with my code, While I run this code it generates memory pressure issue and crash the app.


Functionality is:


I load all the images from server and local assets and match each other with file name and remove duplicate images from list, So it will visible only once.


Any one have solution so please help.


thanks in advance.



asked 1 min ago







Memory Pressure Issue in read Metadata and remove duplicate

Aucun commentaire:

Enregistrer un commentaire