Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7757589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:08:08+00:00 2026-06-01T13:08:08+00:00

I am using following function. Whenever i call it that time it will increase

  • 0

I am using following function. Whenever i call it that time it will increase my memory usage.I have checked all leaks. Even, I am release object immediately at they end of function. Here,I am providing my code for reference. Please, provide guideline.

//Memory at the start of function
Memory in use (in bytes): 38936576

//Memory at the end of function(after pool drain)
Memory in use (in bytes): 39272448

//Function

-(void)parsing:(NSMutableData *)respose
{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
report_memory();
NSString *responseString = [[NSString alloc] initWithData:respose encoding:NSUTF8StringEncoding];

SBJSON *parser = [[SBJSON alloc] init];
//NSLog(@"statuses>>>>>");
statuses = [parser objectWithString:responseString
                              error:nil];

[parser release];
//report_memory();

refreshCounter = YES;
__block NSArray *segment =[[NSArray alloc]initWithArray:[statuses valueForKey:@"Segments"]];

int  mapzoomlevel = [self getZoomLevel];
int polylinewidth = 9;

if(mapzoomlevel == 7) {
    polylinewidth = 1.5;
}
else if(mapzoomlevel == 8) {
    polylinewidth = 2.5;
}
else if(mapzoomlevel ==9) {
    polylinewidth = 3;   
}    
else if(mapzoomlevel ==10) {
    polylinewidth = 3.4;   
}    
else if(mapzoomlevel == 11) {
    polylinewidth = 4;
}    
else if(mapzoomlevel <= 13) {
    polylinewidth = 4.3;
}
else if (mapzoomlevel == 14) {
    polylinewidth = 5.4;
}
else if(mapzoomlevel== 15) {
    polylinewidth = 8;
}

__block CGContextRef    context = NULL;
CGColorSpaceRef colorSpace;
//void *          bitmapData;
int             bitmapByteCount;
int             bitmapBytesPerRow;

bitmapBytesPerRow   = (self.mapView.frame.size.width * 4);
bitmapByteCount     = (bitmapBytesPerRow * self.mapView.frame.size.height);

colorSpace = CGColorSpaceCreateDeviceRGB();
// bitmapData = malloc( bitmapByteCount );

context = CGBitmapContextCreate (NULL,
                                 self.mapView.frame.size.width,
                                 self.mapView.frame.size.height,
                                 8,      // bits per component
                                 bitmapBytesPerRow,
                                 colorSpace,
                                 kCGImageAlphaPremultipliedLast);
CGContextSetAllowsAntialiasing (context,YES);
CGColorSpaceRelease( colorSpace );





CGContextTranslateCTM(context, 0, self.mapView.frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetLineWidth(context, polylinewidth);

CGContextSetAlpha(context, 0.6);
UIColor *color;

for(NSDictionary *route in segment) {

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
    NSString *locations = [route valueForKey:@"Locations"];
    double speed = [[route valueForKey:@"Speed"] doubleValue];

    if (locations && ([locations length]/16 > 1)) {       


        if (speed <= 20) {
            color = [UIColor colorWithRed:222/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
        }
        else if (speed <= 40) {
            color = [UIColor colorWithRed:253/255.0 green:91/255.0 blue:2/255.0 alpha:1.0];
        }
        else if (speed <= 60) {
            color = [UIColor colorWithRed:253/255.0 green:145/255.0 blue:4/255.0 alpha:1.0];
        }
        else if (speed <=80) {
            color = [UIColor colorWithRed:255/255.0 green:212/255.0 blue:4/255.0 alpha:1.0];
        }
        else if (speed >80) {
            color = [UIColor colorWithRed:42/255.0 green:176/255.0 blue:39/255.0 alpha:1.0];
        }

        CGContextSetStrokeColorWithColor(context, color.CGColor);

        for (int i = 0; i <= locations.length - 32; i += 32) {
            NSAutoreleasePool *loc = [[NSAutoreleasePool alloc]init];
            CLLocationCoordinate2D coordinates;
            coordinates.latitude = hexDecode_iPhone([locations substringWithRange:NSMakeRange(i, 16)]);
            coordinates.longitude = hexDecode_iPhone([locations substringWithRange:NSMakeRange(i+16, 16)]);

            CGPoint point = [mapView convertCoordinate:coordinates toPointToView:self.mapView];

            if (i == 0)
                CGContextMoveToPoint(context, point.x, point.y);
            else
                CGContextAddLineToPoint(context, point.x, point.y);
            [loc drain];
        }

        CGContextStrokePath(context);

    } 
    [pool drain];
}       
[segment release];
[polyImage release];
CGImageRef ref = CGBitmapContextCreateImage(context);
polyImage = [UIImage imageWithCGImage:ref];
CGImageRelease(ref);
CGContextRelease(context);
[responseString release];
  __block NWAnotation *nannotation = [[NWAnotation alloc]initWithImage:polyImage
                                          mapView:mapView 
                                      zoomLevel:ZOOM_LEVEL 
                                      aRoadFlag:aRoadFlag
                                      nRoadFlag:nRoadFlag 
                                 othersRoadFlag:othersRoadFlag];

dispatch_queue_t queue1 = dispatch_queue_create("com.MyApp.AppTask",NULL);
dispatch_queue_t main = dispatch_get_main_queue();
dispatch_async(queue1, 
               ^{
                   dispatch_async(main, 
                                  ^{
                                      @try {
                                          //NSLog(@"%d",[queue operationCount]);
                                         [self showpolyline:nannotation];

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

                                  });

               });

dispatch_release(queue1);
dispatch_release(main);
[nwAnotation release];
[nannotation release];
report_memory();
[pool drain];
} 

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:08:09+00:00Added an answer on June 1, 2026 at 1:08 pm

    To identify which objects are causing your memory growth, try performing heapshot analysis using the Allocations tool in Instruments. Check out this blog post for more details.

    As a side note, the way you are releasing the __block variable nannotation is dangerous and will likely lead to a crash at some point. The reason being that __block variables are not automatically retained by dispatch_async and therefore by the time the call to [self showpolyline:nannotation] is made the nannotation object may have already been deallocated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following function that changes a calendar selection at a set time
I am using following function to load the page. I have loads of links
What are the sql exceptions will thrown by using the following function: Read Update
I'm using NetBeans as my IDE. Whenever I have some code that uses another
EDIT: Problem solved by using $i+1 in function call. I have trouble using variables
I am using the following function to show youtube links as videos but the
I am using the following function to loop through a couple of open CDB
I am using the following function to attempt to serialize an object to XML..
I am using the following function to create a simple accordion. The problem is
I am using the following code function xhi(aax) { var aby=document.getElementById(aax); aby.style.bottom=(parseInt(aby.style.bottom)+(screen.height-42)/10)+'px'; if(parseInt(aby.style.bottom)<(screen.height-42))setTimeout('xhi('+aax+')',25); }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.