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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:14:53+00:00 2026-05-15T10:14:53+00:00

Memory management with delegates, it is my understanding that I don’t retain delegates, I

  • 0

Memory management with delegates, it is my understanding that I don’t retain delegates, I am a little unsure about what to do with the delegate if the view gets unloaded (via viewDidUnload) and later recreated (via viewDidLoad)?

@property(assign) SomeClass *someDelegate;

.

- (void)viewDidLoad {
    [super viewDidLoad];
    someDelegate = [[SomeClass alloc] init];
    [someDelegate setDelegate:self];
}

-(void)viewDidUnload {
    [super viewDidUnload];
    [self setSomeDelegate:nil];
}

-(void)dealloc {
[super dealloc];
}

PS: I might be on the wrong track, I am just trying to get my head round this …

cheers Gary

  • 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-15T10:14:54+00:00Added an answer on May 15, 2026 at 10:14 am

    If you use assign for your property, you’re not calling retain on the object.

    This means that you should definitely NOT call release or autorelease on it!

    Your line in your dealloc

    [someDelegate release];
    

    will cause a crash at some point down in the future – you should remove it. You don’t need to care about assigned properties in the dealloc method.

    Your line

    [self setSomeDelegate:nil];
    

    will not leak.


    However, you seem to have [[someDelegate alloc] init] in your viewDidLoad method. This is unusual; it’s normal for the delegate to be an external object, not one made by yourself. In your case, it’s not really a delegate, it’s just an object that does something for you – you should rename it and change the property to a retain (and remember to release it in dealloc).

    Currently, if your property is set to (assign) and someone else sets it, you will leak your initial delegate. If you only use the delegate inside this class, perhaps it shouldn’t be a property at all? If you just want to be able to read it from outside your class you might be able to use (readonly) instead of assign (and change [self setSomeDelegate:nil] to someDelegate=nil;)

    Your line in viewDidUnload that sets the delegate to nil removes the issue you raise in your second comment – you’re removing the delegate so by the time you get to viewDidLoad again, your delegate is already nil 🙂

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

Sidebar

Related Questions

I have a C++ memory management doubt, that's (obviously) related to references and pointers.
I have a quick question regarding memory management that I am not quite sure
What are the memory management checks that XCode does ?
Very basic question about iPhone memory management: Say I have a viewController with several
I've got one question about the memory management of the NSMutableArray . I create
Just came across this website . Feature 9 is memory management and they claim
I'd like to gain better knowledge of operating system internals. Process management, memory management,
I have a memory buffer corresponding to my screen resolution (1280x800 at 24-bits-per-pixel) that
C++ is all about memory ownership - aka ownership semantics . It is the
Still new to the memory management in iPhone apps, I have a newbee question.

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.