English 中文(简体)
• 如何解决Peter SDK 3.1.3的有价连接? - 简编——家庭预算表
原标题:How to solve a deallocated connection in iPhone SDK 3.1.3? - Streams - CFSockets

三. 执行进展 我发现了一个记忆泄漏问题。 我知道问题在哪里,但不幸的是,我试图解决该问题,但没有成功。 我将努力向各位解释,也许你们的某个人可以帮助这样做。

First I have two classes involved in the issue, the publish class (where publishing the service and socket configuration is done) and the connection (where the socket binding and the streams configuration is done). The main issue is in the connection via native socket. In the publish class the "server" accepts a connection with a callback. The callback has the native-socket information. Then, a connection with native-socket information is created. Next, the socket binding and the streams configuration is done. When those actions are successful the instance of the connection is saved in a mutable array. Thus, the connection is established.

static void AcceptCallback(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info) {
  Publish *rePoint = (Publish *)info;

  if ( type != kCFSocketAcceptCallBack) {
   return;
  }
  CFSocketNativeHandle nativeSocketHandle = *((CFSocketNativeHandle *)data);
  NSLog(@"The AcceptCallback was called, a connection request arrived to the server");
  [rePoint handleNewNativeSocket:nativeSocketHandle];
}
- (void)handleNewNativeSocket:(CFSocketNativeHandle)nativeSocketHandle{
 Connection *connection = [[[Connection alloc] initWithNativeSocketHandle:nativeSocketHandle] autorelease]; // Create the connection
 if (connection == nil) {
  close(nativeSocketHandle);
  return;
 }
 NSLog(@"The connection from the server was created now try to connect");
 if ( ! [connection connect]) {
  [connection close];
  return;
 }

 [clients addObject:connection];  //save the connection trying to avoid the deallocation
}

下一步是从客户那里获得信息,因此,根据既定联系信息,可以启动再向下。 但是,当追随者试图利用这一联系时,就会出现错误,他说,这种联系是分配的。 这里的问题是,我不知道联系的地点和时间,不知道联系如何。 我使用了夸张,但经过一些审判后,我看不到更多的信息。

void myReadStreamCallBack (CFReadStreamRef stream, CFStreamEventType eventType, void *info) {
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  Connection *handlerEv = [[(Connection *)info retain] autorelease];   // The error -[Connection retain]: message sent to deallocated instance 0x1f5ef0 (Where 0x1f5ef0 is the reference to the  established connection)
  [handlerEv readStreamHandleEvent:stream andEvent:eventType];
 [pool drain];

}

void myWriteStreamCallBack (CFWriteStreamRef stream, CFStreamEventType eventType, void *info){
 NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
   Connection *handlerEv = [[(Connection *)info retain] autorelease];  //Sometimes the error also happens here, I tried without the pool, but it doesn t help neither.
                  [handlerEv writeStreamHandleEvent:eventType];
 [p drain];

}

令人有些奇怪的是,当我管理着错开(有断点)时,一切都很好,连接没有被分配,接线工作被罚款,服务器能够收到电文。 我将赞赏任何 h!

问题回答

我将自动释放从此线移走:

Connection *handlerEv = [[(Connection *)info retain] autorelease];

现在似乎在工作,但我将尝试更多事情,因为我不相信何时获释,如果我会产生“副作用”。

请指出什么内容非常有用!





相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签