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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:36:07+00:00 2026-06-10T21:36:07+00:00

I have as property in a view, an array of array like this: @interface

  • 0

I have as property in a view, an array of array like this:

@interface MyView : UIView

@property (nonatomic) CGPoint **matrix;

@end

in the controller that own this view I have load the data in the -viewDidLoad and free memory in the -viewDidUnload like this:

- (void)viewDidLoad
{

    self.myView.matrix = malloc(sizeof(CGPoint*) * array1Size);
    for (int k = 0; k < array1Size; k++) {
        self.myView.matrix[k] = malloc(sizeof(CGPoint) * innerArraySize);
    }
}

- (void)viewDidUnload
{
    for (int k = 0; k < array1Size; k++) {
        free(self.myView.matrix[k]);
        self.myView.matrix[k] = nil;
    }
    free(self.myView.matrix);
    self.myView.matrix = nil;
    [self setMyView:nil];
    [super viewDidUnload];
}

While profiling I see a leak here. Can someone help me where I’m wrong?

thanks

update:

i try to remove free code from viewDidUnload and use dealloc like this:

-(void)dealloc {
    [self freeArray];
}

- (void) freeArray {

    for (int k = 0; k < 5; k++) {
        free(self.myView.matrix[k]);
        self.myView.matrix[k] = NULL;
    }

    free(self.myView.matrix);
    self.myView.matrix = NULL;
}

then I embed init code in:

if (self.graphView.matrix == NULL) {
    ...
}

now no more leak, 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-10T21:36:09+00:00Added an answer on June 10, 2026 at 9:36 pm

    Your code does not make sure that each setup of the matrix is matched by exactly one tear down. For example, viewDidUnload is not guaranteed to be called. Also, you have no guards against duplicate setup or tear down.

    If you really need the C array of arrays, a better approach would be to create it in the initializer of the view (initWithFrame: or initWithCoder:) and remove it in its dealloc.

    Edit: To alleviate your concerns regarding dealloc and ARC:

    You can certainly override dealloc in ARC and rely on it being called. The only difference is that you cannot explicitly call the overridden implementation ([super dealloc]). ARC will insert that for you.

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

Sidebar

Related Questions

I have a simple Answer class that looks like this: @interface Answer : NSObject
So i have two view controller in FirstViewController and SecondViewController in FirstViewController NSMutableArray *array;
Let's say I have a service whose interface is something like this: public interface
I have a View that displays the Customer Details. I would like to display
I'm using ember 1.0 pre and have a basic array controller that starts out
I have a property in my view model which returns a constant under some
i have a doubt in grid view. In Data list we have a property
I have a boolean property IsActive. In the view is a list of objects
i have small query as follows: If i will make view state property of
How do I bind a view model property to the ListBox.SelectedItem property? I have

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.