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

  • Home
  • SEARCH
  • 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 7049505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:01:30+00:00 2026-05-28T03:01:30+00:00

I wrote a class, which acts as a filter. I pass three objects: An

  • 0

I wrote a class, which acts as a filter. I pass three objects:

  1. An NSArray, which holds objects to filter (these objects have a timestamp property)
  2. An NSMutableArray (which will hold the section names for a tableView, the periods based on timestamps). I need this array, because I have to sort the periods.
  3. An NSMutableDictionary, in which the keys will be the section names, the values are NSMutableArrays, which hold the items for a given period.

In the class from which I pass these objects, there is a tableView, in which I display the items.
This class has it own NSMutableArray and NSMutableDictionary, I not initialize them, only retain the corresponding return values of the filter class. In the delloc method I release them. There is a method in the filter class:

+ (void)insertItem:(id)item forPeriod:(NSString *)period toContainer:(NSMutableDictionary *)container {

    if ( ![[container allKeys] containsObject:period] ) {

        // the period isn't stored, create and store it
        NSMutableArray *periodArray = [[NSMutableArray alloc] init];
        [container setObject:periodArray forKey:period];
        [periodArray release];
        periodArray = nil;
   }

   // store the item
   NSMutableArray *arrayForPeriod = [container objectForKey:period];
   [arrayForPeriod addObject:item];
   arrayForPeriod = nil;
}

The instruments shows me leak when I set the newly allocated array as an object of the dictionary. At this point this is definitely true, because the dictionary retains again the array, so after the release, it retain count remains 1. But I think in the caller class when I release the dictionary, the array will be released too. Am I wrong?

  • 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-28T03:01:31+00:00Added an answer on May 28, 2026 at 3:01 am

    Yes it is considered as a leak because your var is a local variable. Then you still have an object in memory but no reference to it. Remember the init makes a retain + the retain made by the dictionary = 2 retains. Just create your array using

    NSMutableArray *periodArray = [[[NSMutableArray alloc] init]
    autorelease]

    Is it clear ?

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

Sidebar

Related Questions

I have a REST web service class which i call HttpRequest using curl.I wrote
I have wrote a class (a snippet is below) which have some data members
I recently wrote a class for an assignment in which I had to store
I wrote a code sometime ago in which the object of ResultSet class res
I wrote a PHP CUrl Class, if i execute Methods which should return the
I recently wrote a DLL in C# (.Net 2.0) which contains a class that
Okay, so i have this code i wrote: class Connection { public static StreamWriter
I maintain an application which acts as a container for multiple individual programs. These
I've the class Directory which does stuff with objects of class File, and overloaded
I have a class that essentially acts as a light weight wrapper class around

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.