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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:40:35+00:00 2026-05-13T11:40:35+00:00

I have a weird memory leak with NSTimeIntervall and NSDate. Here is my code:

  • 0

I have a weird memory leak with NSTimeIntervall and NSDate. Here is my code:

NSTimeInterval interval = 60*60*[[[Config alloc] getCacheLifetime] integerValue];
NSDate *maxCacheAge = [[NSDate alloc] initWithTimeIntervalSinceNow:-interval];

if ([date compare:maxCacheAge] == NSOrderedDescending) {
    return YES;
} else {
    return NO;
}

date is just an NSDate object, this should be fine. Instruments tells me that “interval” leaks, yet I do not quite understand this, how can I release a non-object? The function ends after the code snippet I posted here, so from my understanding interval should get automatically deallocated then.

Thanks a lot!

  • 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-13T11:40:36+00:00Added an answer on May 13, 2026 at 11:40 am

    It is probably telling you that a leak is happening on that line.

    The expression [[[Config alloc] getCacheLifetime] integerValue] is your problem.

    First of all, you care creating an object (calling alloc) but you lose the reference to it before calling release or autorelease, so it is leaking.

    Also, you really ought to call an init method immediately after allocating the object. Even if your Config class doesn’t do anything special, NSObject‘s init method will need to be called.

    If you replace that line with

    Config *config = [[Config alloc] init];
    NSTimeInterval interval = 60*60*[[config getCacheLifetime] integerValue];
    [config release];
    

    That leak should be plugged up.

    You are also leaking the maxCacheAge object. Inserting [maxCacheAge autorelease]; before the if statement should fix that.

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

Sidebar

Related Questions

I have been getting a weird memory leak and i just pinpointed what is
I'm getting a weird problem in memory deallocation. I have the following code for
I have seen some very weird for loops when reading other people's code. I
I'm trying to work with GDI+ and I'm running into a weird memory leak.
I have a weird date rounding problem that hopefully someone can solve. My client
I have a weird issue that only seems to be affecting IE 7. The
I have a weird error in my C++ classes at the moment. I have
We have a weird intermittent problem with saving from Word 2007 to our SharePoint
i have a weird problem. i would like to delete an assembly(plugin.dll on harddisk)
I have a weird problem with images in visual web developer, I cant change

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.