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 6773017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:37:02+00:00 2026-05-26T15:37:02+00:00

I was trying to remove the memory leaks in my app but i found

  • 0

I was trying to remove the memory leaks in my app but i found out that while using the alloc NSbundle in a for loop it is giving me memory leak.

here is my code:-

in my class myFeed.m


for(int i = 0; i<20; i++)

    {
        NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];

        NSDictionary *temp = (NSDictionary*)[topData objectAtIndex:i];

        NSString *iconName = [temp objectForKey:@"feed_source"];
        NSString *imageName;
        TimeLineGrid *grid = [[TimeLineGrid alloc]initWithNibName:@"TimeLineGrid" bundle:[NSBundle mainBundle]];

        CGRect frame = grid.view.frame;
       if([iconName isEqualToString:@"Youtube"])
           imageName = [[NSBundle mainBundle]pathForResource:@"Youtube" ofType:@"png"];;
         if  (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
         {
             frame.size=CGSizeMake(130, 130);
         }
        else
        {
        frame.size = CGSizeMake(180, 180);
        }
        [grid setDelegate:self];

        if (isConditionTrue) 
        {

            x = x - 200 - topFactor;

        }
        else
            x = x - frame.size.width;

        if (x < 0) 
        {
            x = 0;
        }

        frame.origin.x = x;

        frame.origin.y = y;

        grid.view.frame = frame;

        grid.view.tag = tagCount;

        if ([temp objectForKey:@"feed_item_nid"]) 
        {

            [tagToNIDMap addObject:[temp objectForKey:@"feed_item_nid"]];

        }




        if  ([(NSString*)[temp objectForKey:@"feed_source"]isEqualToString:@"Youtube"])
        {

            [grid.webView loadHTMLString:[self getYoutubeCode:(NSString*)[temp objectForKey:@"feed_item_url"] :grid.webView.frame] baseURL:nil];
        }
        else
        {
            NSString *  str = [[WebServiceController Initialize]parseHTMLData:[temp objectForKey:@"feed_item_body"] : @"//img"];
            NSURL * url  = [NSURL URLWithString:str];
            NSURLRequest * req = [NSURLRequest requestWithURL:url];
            [grid.webView loadRequest:req];
        }

                    //[grid.view addSubview:grid.webView];
        tagCount++;
        [grid setHome:frame];


        grid.dict = (NSDictionary*)[topData objectAtIndex:i];
      //  grid.icon.frame=CGRectMake(grid.view.frame.origin.x, grid.view.frame.origin.y-20,grid.icon.frame.size.width,grid.icon.frame.size.height)
        grid.icon.image = [UIImage imageNamed:imageName];

        grid.detail.text = [temp objectForKey:@"feed_item_title"];

         [scroll1 addSubview:grid.view];
        [imageName release];
        [grid release];
        [pool release];

    }

}

myGrid is an another class with a .xib which i am trying to load in myFeed class.
but if at the end of the loop i add [grid release] then the view of myGrid can be seen but the UiwebView present in myGrid does not show its data.
And the instrument is also showing memory leak at the line :

myGrid *grid = [[myGrid alloc]initWithNibName:@"myGrid" bundle:[NSBundle mainBundle]];

what i am doing wrong here…

  • 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-05-26T15:37:02+00:00Added an answer on May 26, 2026 at 3:37 pm

    You aren’t doing anything with all those myGrid objects (class names should start with a capital letter, by the way). Your loop creates a view controller, loads something into it’s webView property, and then releases it, which is pointless.

    I assume you are doing something with grid after this loop has finished – what is that? If you really need 20 different myGrid objects then you need to add them to an array or something during your loop, because at the moment you are just overwriting the value of grid every time your loop processes. If you remove the release statement then you will have a single myGrid object at the end of the loop, and 19 leaked instances from the other passes.

    If you want a single grid object then create it before the loop begins – but it looks like that would just end up with a single object that is configured however you set it during the last iteration of the loop.

    UPDATE

    OK, now you’ve included your full code it is a bit clearer. You need to keep around each grid object. Create an NSMutableArray before your for loop (this should probably be a property of whatever object this code is in):

    self.gridArray = [NSMutableArray array];
    for (... // your loop here
    

    Within the loop, before you release grid, add the following:

    [self.gridArray addObject:grid];
    [grid release];
    

    This prevents you losing the reference to each grid object except the last one, and stops you leaking memory in this code. You can later release or modify the objects in your gridArray as you see fit.

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

Sidebar

Related Questions

I've spent the last few days trying to remove memory leaks in my game,
We are trying to figure out if we have memory leaks in our software.
I've been trying to get rid of memory leaks in mapview. I am using
I'm trying to remove all but the first child component from a Java Container.
I am trying to remove a directory with rmdir , but I received the
I am trying to remove the attribute xmlns=http://webdev2003.test.com from the following xml using xsl/xslt,
I'm trying to optimize memory usage of a program and therefore wants to remove
I'm trying to figure out the best option to use anonymous event listeners that
I'm trying to create a simple game, but I can't find a certain memory
I'm trying to remove non-matching results from a memory scanner I'm writing in C++

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.