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.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi,
I’m using Network Framework to implement a UDP client via NWConnection, and I’m looking for clarification about the correct and fully safe shutdown procedure, especially regarding resource release.
I have initiated some pending receive calls on the NWConnection (using receive). After calling connection.cancel(), do we need to wait for the cancellation of these pending receives?
As mentioned in this thread, NWConnection retains references to the receive closures and releases them once they are called. If a receive closure holds a reference to the NWConnection itself, do we need to wait for these closures to be called to avoid memory leaks? Or, if there are no such retained references, we don't need to wait for the cancellation of the pending I/O and cancelled state for NWConnection?
I am trying to use the swift type UnsafeMutablePointer directly in C++. According to the documentation mentioned, swift expose this type to C++. But I am not able to use it .
void
GetPointerFromSwift () {
// Calls a swift function to get a pointer.
swift::UnsafeMutablePointer<swit::Int> x = Interop::GetPointer ()
}