title: A memory leak, could my problem be with pointers [swift]
body: <p>iOS 12.x Swift 5</p>
  
  <p>I am using sockets to talk to another box and I wrote this code which I think makes sense. but I wanted to check with an expert. I ask cause I think I have some sort of memory leak with this app. And I suspect pointers, as you do. I am watching the memory it uses slowly increase as I am running it.</p>
  
  <pre><code>func sendMessage(message: String) {
  
      let data = message.data(using: String.Encoding.utf8, allowLossyConversion: false)!
      let dataMutablePointer = UnsafeMutablePointer&lt;UInt8&gt;.allocate(capacity: data.count)
      //Copies the bytes to the Mutable Pointer
  
      dataMutablePointer.initialize(to: 0)
      data.copyBytes(to: dataMutablePointer, count: data.count)
  
      //Cast to regular UnsafePointer
      let dataPointer = UnsafePointer&lt;UInt8&gt;(dataMutablePointer)
  
      //Your stream
      outputStream.write(dataPointer, maxLength: data.count)
      defer {
        dataMutablePointer.deinitialize(count: data.count)
      }
  }
  </code></pre>
  
  <p>Does this code look sane? Could it be the source of my memory leak? Do I need to deinitalize this pointer?</p>