I am using withUnsafeMutablePointer to get raw pointer from Data. Once I get a Pointer I follow these steps:
I create a Wrapper using that Pointer.
After that I increase it ARC and pass it as a opaque to C++
When I was on First Step if my thread get suspended and after some time if it resumes then is there a possibility that the Memory will get freed due to ARC.
Adding basic Code Flow depicting what i am doing.
public class DataHolder {
public init () {}
public var data_wrapper : Data?
}
func InternalReceiveHandler (_ pContent : Data?) -> Void {
var holder : DataHolder = DataHolder.init ()
withUnsafeMutablePointer (to : &pContent) { data_pointer in
holder.data_wrapper = Data.init (noBytesCopy : data_pointer, count : no_of_bytes, deallocator : .none)
return Unmanaged.passRetained (holder).toOpaque ()
}
}
Is there a possibility that when I am creating the wrapper my thread get suspended and when it get resumed the Memory the pointer was pointing can be freed by ARC.
5
0
878