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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:27:01+00:00 2026-06-15T02:27:01+00:00

I have a small issue with memory with the current code I have written,

  • 0

I have a small issue with memory with the current code I have written, I’m new to cocoa and programming with object orientated languages, so currently Xcode does all the memory management stuff for me, however that’s not helping me right now.

The problem currently is that I am creating a NSTableView and it has pictures in each cell that update in 0.5s intervals, this is fine, however each time the image get’s loaded a new NSImageView object gets created (this is were i think the memory issue is, correct me if I’m wrong), how ever I lack a solution to this problem. This is causing the memory usage to be increased by about 5MB per 0.5s and so after 10 minutes or so the application will be taking up a large portion of my computers memory. I don’t know how to get rid of the created NSImageView objects after they are useless, without causing the images to be delayed during the display process…

This is the current code:

-(void)play_view:(NSInteger)view{
     valid_times_counter = valid_times_counter + 1;
     if(valid_times_counter == ([valid_times count]-2)){
         valid_times_counter = 1;
     }
     [self performSelector:@selector(reload_table_data) withObject:self afterDelay:0.5];
}

-(void)reload_table_data{
    [view_table removeFromSuperview];
    [self addSubview:view_table];
    [view_table reloadData];
    [self play_view:valid_times_counter];
}

- (void)drawRect:(NSRect)dirtyRect
{
NSLog(@"drawing"); //Table being drawn, probably not relevant but just in case ;)

[[NSColor colorWithCalibratedRed:0.01f green:0.40f blue:0.69f alpha:1.00f]setFill];
NSRect bg = NSMakeRect(0, 0, self.frame.size.width, self.frame.size.height);
NSRectFill(bg);

if(level == 1){
    NSLog(@"draw_table Level 1");
    [view_table removeFromSuperview];
    [self setFrameSize:NSMakeSize(2048, 1024)];
    view_table = [[NSTableView alloc]initWithFrame:NSMakeRect(0, self.frame.size.height-1024, 2048, 1024)];
    for(int c = 0; c<4;c++){
        NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:[NSString stringWithFormat:@"%i",c]];
        [[column headerCell] setStringValue:[NSString stringWithFormat:@"%i",c]];
        [column setWidth:512.0];
        [view_table addTableColumn:column];
    }
    [view_table setRowHeight:512];
    [view_table setDelegate:(id)self];
    [view_table setDataSource:(id)self];
    [view_table setIntercellSpacing:NSMakeSize(0, 0)];
    [view_table setIdentifier:@"view_table"];
    [view_table reloadData];

    [self addSubview:view_table];

}
else if(level == 2){
    NSLog(@"draw_table Level 2");
    [view_table removeFromSuperview];
    [self setFrameSize:NSMakeSize(4096, 2048)];
    view_table = [[NSTableView alloc]initWithFrame:NSMakeRect(0, self.frame.size.height-2048, 4096, 2048)];
    for(int c = 0; c<8;c++){
        NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:[NSString stringWithFormat:@"%i",c]];
        [[column headerCell] setStringValue:[NSString stringWithFormat:@"%i",c]];
        [column setWidth:512.0];
        [view_table addTableColumn:column];
    }
    [view_table setRowHeight:512];
    [view_table setDelegate:(id)self];
    [view_table setDataSource:(id)self];
    [view_table setIntercellSpacing:NSMakeSize(0, 0)];
    [view_table setIdentifier:@"view_table"];
    [view_table reloadData];

    [self addSubview:view_table];
}
else if(level == 3){
    NSLog(@"draw_table Level 3");
    [view_table removeFromSuperview];
    [self setFrameSize:NSMakeSize(8192, 4096)];
    view_table = [[NSTableView alloc]initWithFrame:NSMakeRect(0, self.frame.size.height-4096, 8192, 4096)];
    for(int c = 0; c<16;c++){
        NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:[NSString stringWithFormat:@"%i",c]];
        [[column headerCell] setStringValue:[NSString stringWithFormat:@"%i",c]];
        [column setWidth:512.0];
        [view_table addTableColumn:column];
    }
    [view_table setRowHeight:512];
    [view_table setBackgroundColor:[NSColor clearColor]];
    [view_table setDelegate:(id)self];
    [view_table setDataSource:(id)self];
    [view_table setIntercellSpacing:NSMakeSize(0, 0)];
    [view_table setIdentifier:@"view_table"];
    [view_table reloadData];

    [self addSubview:view_table];
}
else if(level == 4){
    NSLog(@"draw_table Level 4");
    [view_table removeFromSuperview];
    [self setFrameSize:NSMakeSize(16384, 8192)];
    view_table = [[NSTableView alloc]initWithFrame:NSMakeRect(0, self.frame.size.height-8192, 16384, 8192)];
    for(int c = 0; c<32;c++){
        NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:[NSString stringWithFormat:@"%i",c]];
        [[column headerCell] setStringValue:[NSString stringWithFormat:@"%i",c]];
        [column setWidth:512.0];
        [view_table addTableColumn:column];
    }
    [view_table setRowHeight:512];
    [view_table setDelegate:(id)self];
    [view_table setDataSource:(id)self];
    [view_table setIntercellSpacing:NSMakeSize(0, 0)];
    [view_table setIdentifier:@"view_table"];
    [view_table reloadData];

    [self addSubview:view_table];
}
else if(level == 5){
    NSLog(@"draw_table Level 5");
    [view_table removeFromSuperview];
    [self setFrameSize:NSMakeSize(32768, 16384)];
    view_table = [[NSTableView alloc]initWithFrame:NSMakeRect(0, self.frame.size.height-16384, 32768, 16384)];
    for(int c = 0; c<64;c++){
        NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:[NSString stringWithFormat:@"%i",c]];
        [[column headerCell] setStringValue:[NSString stringWithFormat:@"%i",c]];
        [column setWidth:512.0];
        [view_table addTableColumn:column];
    }
    [view_table setRowHeight:512];
    [view_table setBackgroundColor:[NSColor clearColor]];
    [view_table setDelegate:(id)self];
    [view_table setDataSource:(id)self];
    [view_table setIntercellSpacing:NSMakeSize(0, 0)];
    [view_table setIdentifier:@"view_table"];
    [view_table reloadData];

    [self addSubview:view_table];
}


//Problem section
-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{

if([tableView.identifier isEqualToString: @"view_table"]){
    NSLog(@"---------VIEW---------");
    NSView *view = [tableView makeViewWithIdentifier:@"MyView2" owner:self];
    [tableView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];

    if (view == nil) {
        view = [[NSView alloc]initWithFrame:NSMakeRect(0, 0, 512, 512)];
        NSString *table_id;
        if([tableColumn.identifier integerValue]<10){
            table_id = [NSString stringWithFormat:@"000%@",tableColumn.identifier];
        }
        else if([tableColumn.identifier integerValue]<100){
            table_id = [NSString stringWithFormat:@"00%@",tableColumn.identifier];
        }
        else if([tableColumn.identifier integerValue]<1000){
            table_id = [NSString stringWithFormat:@"0%@",tableColumn.identifier];
        }
        NSString *row_id;
        if(row < 10){
            row_id = [NSString stringWithFormat:@"000%li",row];
        }
        else if(row < 100){
            row_id = [NSString stringWithFormat:@"00%li",row];
        }
        else if(row < 1000){
            row_id = [NSString stringWithFormat:@"0%li",row];
        }

        if([valid_times count]>1){
            image_view2 = [[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 512, 512)]; //This gets repeated every 0.5s, and this is what is causing the problem I think...
            NSString *url_str = [self get_url:(valid_times_counter):table_id:row_id];
            NSLog(@"Loading Image from: %@", url_str);
            NSImage *map_tile2 = [[NSImage alloc] initWithContentsOfFile:url_str];
            [image_view2 setImage:map_tile2];
            [view addSubview:image_view2];
        }
        else{
            //No Views found
            NSLog(@"ERROR, NO IMAGES FOUND 348.map_view.h-tableView.viewForTableColumn:row For data %@", [valid_times objectAtIndex:0]);
        }
    }
    return view;

I have commented the section in the code where I think the problem is, does any one know a solution, I thought of just changing the contents of the cell instead of reloading the table data every time, but I don’t really know how to do that.

If you require more detail just ask, I’d be great full about any ideas…

  • 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-15T02:27:03+00:00Added an answer on June 15, 2026 at 2:27 am

    On each line, you seem to be re-allocating your table view.

    view_table = [[NSTableView alloc]initWithFrame:NSMakeRect(0, self.frame.size.height-4096, 8192, 4096)];
    

    Leaving aside the extremely odd numbers for the frame size, you should not be recreating your table view. If you want to reload the data, just call -reloadData, but do not keep removing and adding the table view. I don’t know if you’re using ARC or not, but most likely your problem is that you’re not releasing the old memory that the table view took up, but instead you’re assigning a new instance to the old ivar. The old instance is still hanging around somewhere, but you cannot access it because you’ve reassigned the pointer.

    You’re also doing all this strange reloading stuff in -drawRect: which is horrible for so many reasons.

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

Sidebar

Related Questions

I am just new to programming in Unix and have a small issue that
To put it mildly I have a small memory issue and am running out
I have a small issue with sessions. I have built a small shopping cart-esque
I have a small issue with a method that should save the text contained
I have a small issue(for lack of a better word) with MySQL db. I
i have a small issue which my text field insist to inhert the CSS
can anyone help, i have a small issue, i have an interface and also
I have run into a small issue in my program. I have a class
everything is working fine with my jqgrid except a small issue. i have defined
I'm building a MonoTouch iPhone app, but have come up with a small issue.

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.