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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:30:53+00:00 2026-05-22T14:30:53+00:00

Anyone able to help re what is the source of the leaky object for

  • 0

Anyone able to help re what is the source of the leaky object for this code:

My application compiles without any ANALYZE issues. When I run PROFILER and look at Memory Leaks I see leaks appears. One of these leaks is in my WeekendEvent object. There are 3 Leaked Block row items in instruments per the below (I’ve noted in the code where these point to):

  • Malloc +1
  • Retain +2
  • Release +1

Question – I assume this implies there is a release, however where would this leak be from. The segments of my code that clicking through on instruments highlights is below. To me it seems OK in that:

  1. the WeekendEvent I create I release after passing into the addWeekendEvent method
  2. in the addWeekendEvent it just adds it to a NSMutableArray, and hence I thought the arrange does any memory management for it’s object it contains
  3. I do release the NSMutableArray in the dealloc too

Key Source Code Bits & What Instuments Highlights

// ------Weekends Method (plural)-----
WeekendEvent *weEvent = [[WeekendEvent alloc] init]; // [INSTRUMENTS - 87.5%]
[week addWeekendEvent:weEvent];                      // [INSTRUMENTS - 12.5%]
[weEvent release];                  


//------Weekend *.h ------------
@interface Weekend : NSObject {
    NSMutableArray*     _events;     
}
- (void)addWeekendEvent:(WeekendEvent*)weEvent;
@property (nonatomic, retain) NSMutableArray* events;
@end


//------Weekend *.m -------------
- (void)addWeekendEvent:(WeekendEvent*)weEvent {
    [self.events addObject:weEvent];
}
- (void) dealloc {
    [_events release];
    [super dealloc];
}

EDIT: Some additional code re how the “week” variable above was created/used – so in the Weekends Method the code I posted was within a for loop – the code with the for loop shown therefore was:

for (Weekend *week in self.items) {
   // do pass "week.start" to some methods (which is an NSDate) - don't think this would be relevant though?
   WeekendEvent *weEvent = [[WeekendEvent alloc] init]; // [INSTRUMENTS - 87.5%]
   [week addWeekendEvent:weEvent];                      // [INSTRUMENTS - 12.5%]
   [weEvent release];   
}               
// Note - self.items I checked is "released" in the dealloc method

EDIT 2 – Just to confirm, it is an “WeekendEvent” instance that Instruments highlights in it’s “leaked objects” column. Just in case this wasn’t clear.

EDIT 3 – Re how I setup the items variable – key code bits are:

@interface Weekends : NSObject {
    NSMutableArray* _items;
}
@property (nonatomic, retain) NSMutableArray* items;

@synthesize items = _items;
- (void) dealloc {
    [_items release];
    [super dealloc];
}
  • 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-22T14:30:54+00:00Added an answer on May 22, 2026 at 2:30 pm

    The memory management in the code you show is correct, assuming that the rest of your Weekend class looks something like this:

    @synthesize events = _events;
    
    - (id)init {
        if ((self = [super init]) == nil) { return nil; }
        _events = [[NSMutableArray alloc] initWithCapacity:0];
        return self;
    }
    

    Also, the instruments results match all of your code:

    Malloc  +1  ==  WeekendEvent *weEvent = [[WeekendEvent alloc] init];
    Retain  +2  ==  [week addWeekendEvent:weEvent];
    Release +1  ==  [weEvent release];
    

    Based on that logic, the most likely candidate is that your week object is not properly released. You haven’t shown the code that explains how it was created, but I do notice that the code you did post is for a Weekend class. Are you sure week is not of a different type?

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

Sidebar

Related Questions

I was wondering if anyone would be able to help me fix this script...It
FYI I'm programming in objective-C but anyone might be able to help. I've been
Has anyone been able to get xinc to run correctly under OpenBSD's chrooted default
I am able to pull down the latest android source code into a Ubuntu
Does anyone have any ideas why a test would pass when run with ant,
Does anyone know of a utility to preprocess a C# source file without compiling
anyone able to tell me how often a materialized view is set to refresh
Has anyone been able to get an NHibernate-based project up and running on a
Has anyone been able to get a variable record length text file (CSV) into
Has anyone been able to successfully unit test methods that are, by necessity, coupled

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.