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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:02:12+00:00 2026-05-20T18:02:12+00:00

I have UITableViewCell s that have an imageView that loads a UIImage from a

  • 0

I have UITableViewCells that have an imageView that loads a UIImage from a model object myObject. The UIImage property on myObject is loaded asynchronously and I observe changes to it from the tableViewCell to know when I can reload it (and replace the placeholder image). Here is my problem secenario:

  1. User performs a search, which populates an array of model objects
  2. Those model objects are represented in UITableViewCells, and the iconImg property is observed for async download completion. (This works great, so far).
  3. If the user does another search, I discard those original model objects, and that results in a “An instance of class Merchant was deallocated while key value observers were still registered with it” message, which doesn’t sound good.

The dealloc methods for my UITableViewCells unregister the cell, but that isn’t called when I dealloc the underlying model in the scenario above. Is there a clean way to tell my cells to unregister when the observed instance deallocs? Can I just remove all observers in the model object’s dealloc?

Side question: why doesn’t KVO automatically remove registered observers from an object when it deallocs?

  • 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-20T18:02:12+00:00Added an answer on May 20, 2026 at 6:02 pm

    UPDATE: see my comment for the best way to fix this. That said, to understand what’s happening, this question is still informative…(end update)

    Solved (at least in my case). Here is what was happening:

    My view controller is used for displaying search results, and it stores those search results as an array of model objects. I use a custom UITableViewCell subclass to display each search result and, as part of configuring it, I store the associated model object (search result) within a property of the custom cell, call it myCell.modelObject.

    As I noted, the error was happening on every search except the initial one. To debug, I set a symbolic breakpoint on NSKVODeallocateBreak and saw that this was happening upon re-using one of my custom cells:

    - (void)configureWithModelObject:(ModelObject*)aModelObject {
        // @property (nonatomic, retain) ModelObject *modelObject;
        self.modelObject = aModelObject;  // <-- NSKVODeallocateBreak paused here
        ....
    }
    

    So, my view controller, upon getting a second search result set, would release the array containing the original search’s model objects. Those still retained by my re-usable custom cell instances would stick around, at least until those cells were re-used again. At that point, when self.modelObject is updated, the previous modelObject is released again and finally deallocates but because the cell that was observing it was not deallocated, but instead was re-used, my [modelObject removeObserver…] call in [myCell dealloc] was not called.

    Solution: When configuring my custom cell, I need to check if the model object is already set, which is an indication that this cell is being re-used. If so, I stop observing the original modelObject before updating the property:

    - (void)configureWithModelObject:(ModelObject*)aModelObject {
        if(modelObject != nil) {
            // I'm being re-used! Stop observing old model object!
            [modelObject removeObserver:self forKeyPath:@"keyPathIWasObserving"];
        }
        self.modelObject = aModelObject;  // <-- NSKVODeallocateBreak paused here
        ....
    

    Note: I still need to call [modelObject removeObserver…] in [cell dealloc] to handle the situation where the view controller itself deallocates.

    I hope this is helpful to others with a similar pattern.

    Best,
    Steve

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

Sidebar

Related Questions

I have found that the first time a UITableView loads, it does not respond
I have a grouped UITableView that contains several cells (just standard UITableViewCell s), all
I have successfully placed an image into the lefthand ImageView of a default UITableViewCell
I have a UITableView with standard UITableViewCells that contain an image on the left.
I'm trying to set up a UITableViewCell that can have an image in the
I've got a custom UITableViewCell class whose model object performs an asynchronous download of
I have a UILabel in a custom UITableViewCell that gets resized when the device
I want to use UITableViewCells within my application which have an image, and that
I have a UITableView cell that is going to have a variable size depending
In my application I have a UITextField inside a UITableViewCell . If I click

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.