GCDAsyncSocket in SWIFT exhausted Memory

711 views
Skip to first unread message

Werner Hövelmanns

unread,
Sep 13, 2015, 9:37:06 AM9/13/15
to CocoaAsyncSocket
Hi Everybody,

I use the Following Code in my Project and it works....
but my Server continuosly send a status string to my client( the App).
Everytime GCDAsyncSocket received the Information a buffer is send the delegetad class.
This buffer is allocated in GCDAsynSocket, but I wonder how to dealloc this buffer in Swift.

Could anybod help me?

regards

Werner

 
  func connect
() {
    tcpSocket
= GCDAsyncSocket(delegate: parent, delegateQueue: dispatch_get_main_queue())
   
var error: NSError?
   
if (!tcpSocket!.connectToHost(myHost, onPort: myPort, error: &error))        {
      println
("Error \(error)")
   
} else {
      println
("Connecting...")
   
}
 
}
 
  func socket
(socket : GCDAsyncSocket, didConnectToHost host:String, port p:UInt16) {
    println
("Connected to \(host) on port \(p).")
    isConnected
=true
 
}
 
  func socket
(socket : GCDAsyncSocket, didReadData data:NSData, withTag tag:UInt16) {
    let response
= NSString(data: data, encoding: NSUTF8StringEncoding)
   
if(response != nil){
      changeStatus
(response!)
   
}
 
}




PayMobile

unread,
Sep 14, 2015, 2:04:12 AM9/14/15
to cocoaasy...@googlegroups.com
Hi Werner,

You cannot. Swift uses "smart pointers" that means an object instance
get deallocated once the references count get 0. If there are memory
leaks they are not being caused by your code, as I see. If the buffer
"data" is not retained by the library then it will be released
immediately at the end of your callback method. Just start Instruments
and locate where exactly the memory leak occurs.

Regards,

Simon

On 13/09/15 15:37, Werner Hövelmanns wrote:
> Hi Everybody,
>
> I use the Following Code in my Project and it works....
> but my Server continuosly send a status string to my client( the App).
> Everytime GCDAsyncSocket received the Information a buffer is send the
> delegetad class.
> This buffer is allocated in GCDAsynSocket, but I wonder how to dealloc
> this buffer in Swift.
>
> Could anybod help me?
>
> regards
>
> Werner
>
> |
>
> func connect(){
> tcpSocket
> =GCDAsyncSocket(delegate:parent,delegateQueue:dispatch_get_main_queue())
> varerror:NSError?
> if(!tcpSocket!.connectToHost(myHost,onPort:myPort,error:&error)){
> println("Error \(error)")
> }else{
> println("Connecting...")
> }
> }
>
> func socket(socket :GCDAsyncSocket,didConnectToHost host:String,port
> p:UInt16){
> println("Connected to \(host) on port \(p).")
> isConnected=true
> }
>
> func socket(socket :GCDAsyncSocket,didReadData data:NSData,withTag
> tag:UInt16){
> let response =NSString(data:data,encoding:NSUTF8StringEncoding)
> if(response !=nil){
> changeStatus(response!)
> }
> }
>
>
> |
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "CocoaAsyncSocket" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to cocoaasyncsock...@googlegroups.com
> <mailto:cocoaasyncsock...@googlegroups.com>.
> To post to this group, send email to cocoaasy...@googlegroups.com
> <mailto:cocoaasy...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/cocoaasyncsocket/c590ee2d-df65-4569-943a-2560f80b4dc1%40googlegroups.com
> <https://groups.google.com/d/msgid/cocoaasyncsocket/c590ee2d-df65-4569-943a-2560f80b4dc1%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages