1

I'm getting the following error:

SearchStockCell retain]: message sent to deallocated instance 0x7f9fa1922c00

but I am having a hard time tracing the issue because whenever I profile with zombies, it stops without any warning or error(2-3 secs).

enter image description here

I'm using realm for this project and the data parsing is performed at background.Not sure if this information is relevant.

Is there other way to track this? or is possible I use weak for tableview cell?

Updated

class SearchStockCell: SSBaseTableCell {
@IBOutlet var symbolLabel: UILabel!    
@IBOutlet var marketLabel: UILabel!
@IBOutlet var priceLabel: UILabel!

var stock: StockInfo? {
    willSet{ "About to step to \(newValue)"
        if let aStock = newValue {
            // add KVO on newValue
            aStock.addObserver(self,
                forKeyPath: "price",
                options: NSKeyValueObservingOptions.New,
                context: nil)

            aStock.addObserver(self,
                forKeyPath: "change",
                options: NSKeyValueObservingOptions.New,
                context: nil)

        }
    }
    didSet { "Just stepped from \(oldValue)"
        if let aStock = oldValue {
            // remove KVO on old value
            aStock.removeObserver(self, forKeyPath: "price")
        }

        if let aStock = oldValue {
            // remove KVO on old value
            aStock.removeObserver(self, forKeyPath: "change")
        }

        self.configureCell()
    }
}

override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {

    if keyPath == "price" {
        self.updatePrice()
    }

    if keyPath == "change" {
        self.updateChange()
    }

}

.... ... .. .

Here is the code happened in SearchStockCell. I will fire an API to update my visible cells(it will update my realm) which later will prompt the changes on the SearchStockCell by KVO. Note that I can't really reload the table again because I need to maintain the position of tableview and there's thousands rows of data in it.

shoujo_sm
  • 3,173
  • 4
  • 37
  • 60

2 Answers2

1

It is really hard to guess from code but would try my best to look answer Please look for places

  • have used SearchStockCell as a property somewhere if yes check for attributes strong/weak. There is possible cycle of holding each other.
  • Check if you are using SearchStockCell object in block, if yes try using it as weak object. Also check for other things done inside the block.
  • you are using KVO, check if at any point of time is observer going out of memory.

Most likely issue which I can think of right is at some place you are assigning/using SearchStockCell object as weak/strong due to which ARC is handling retain count wrongly.

shim
  • 9,289
  • 12
  • 69
  • 108
aman.sood
  • 872
  • 7
  • 19
0

It looks like you're vastly overcomplicating this situation by adding and balancing KVO on these table cells.

You mentioned that you don't want to reload the table since you'll lose your position in the scroll view. Have you considered simply saving the scroll position of the table view before reloading and then re-setting it afterwards?

As a side note, Realm will soon introduce a feature to track insertions/updates/deletions on a table view data source, so hopefully once that's out, you could use that here instead (Disclaimer: I work for Realm).

TiM
  • 15,812
  • 4
  • 51
  • 79