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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:58:25+00:00 2026-06-01T19:58:25+00:00

I am just cleaning up my code a little bit and I found a

  • 0

I am just cleaning up my code a little bit and I found a few lines in a function where I am not sure if they are producing memory leaks.
I would appreciate any ideas.

Thanks in advance!

In the following code the variables filepath is a NSURL and filename a NSString object defined as properties. The definition attribute is set to “copy”.
Here’s the code :

-(BOOL)isEqual:(id)object
{
    if ( self == object)
        return YES;

    if (!object || ![object isKindOfClass:[self class]]) 
        return NO;

    if ( ![[[self filepath] path] isEqual:[[object filepath] path]])
        return NO;

    if (![[self filename] isEqualToString:[object filename]])
        return NO;

    if (![[self filesize] isEqualToString:[object filesize]])
        return NO;

    if (![[[self filepath ] absoluteURL] isEqual:[[object filepath] absoluteURL]])
        return NO;

    if ( !([[[self filepath ] absoluteURL ] isFileURL ] && [[[object filepath] absoluteURL ] isFileURL ]))
        return NO;

    return YES;
}

From my understanding, a property with the copy attribute would return an object with a retain count of +1. This would mean, that I should have memory leaks on every if-statement.
Is this correct?

  • 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-01T19:58:26+00:00Added an answer on June 1, 2026 at 7:58 pm

    Nothing in your code snippet indicates a leak.

    The copy attribute means that you are keeping a copy of the object with a retain count of one when you are setting the property. You cannot leak it simply by referencing it in your code (even via that property’s accessor).

    On the other hand, ‘filepath’ and ‘filename’ should be released in the -dealloc method of the object in which they are included. Failure to do that (assuming a reference-count memory mode) will result in leaks.

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

Sidebar

Related Questions

I've finished a personal project now just going through my code cleaning things up.
I am cleaning up my code in a phonebook iPhone application and the Leaks
A few days ago I found a nice snippet on SO to test memory
Just wondering if the following is considered to be good programming practice or not?
Just to make sure I'm understanding shallow copies of reference types correctly and that
It's not code-related but IDE related. I'm working on a .NET solution with about
I am cleaning up some code in a C# app that I wrote and
Hey all, I'm working on cleaning up my code from previous semesters. Previously I
Lately, I've been cleaning up some some C code that runs on an ARM7
I'm cleaning up some pretty complicated code that I didn't write and I'm looking

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.