title: iOS Attempted to dereference garbage pointer
body: <p>I am getting iOS crash report from Bugnag:</p>
  
  <blockquote>
    <p>Attempted to dereference garbage pointer 0x8000000000000010</p>
  </blockquote>
  
  <p>Below is the class which I have in my project</p>
  
  <pre><code>class Presence {
      private var userStates = [Int: [String: Any]]()
  
     internal func saveState(state: UserPresenceState, updateTime: Date, for userId: Int) {
          let value = ["state": state, "updated_at": updateTime]
          let queue = DispatchQueue(label: "mySerialQueue")
          queue.sync { 
               self.userStates[userId] = value
          }
      }
  }
  
  </code></pre>
  
  <p>I am getting Attempted to dereference garbage pointer at line <code>self.userStates[userId] = value</code>. Not sure while accessing self or while accessing userStates variable</p>
  
  <p>I am not sure why this is happening and unable to replicate it, how to solve these kinds of problems?</p>
  
  <p>Is there anything know whether a variable is deallocated or not?</p>
  
  <p>Any help much appreciated</p>
  
  <p>FYI
  I got the same error from bugsnag with below code too</p>
  
  <pre><code>internal func saveState(state: UserPresenceState, updateTime: Date, for userId: Int) {
      let value: [String: Any] = ["state": state, "updated_at": updateTime]
      self.userStates[userId] = value
  }
  </code></pre>