Can NSNotificationCenter Memorize Old Events?
Can NSNotificationCenter Memorize Old Events?
- Subject: Can NSNotificationCenter Memorize Old Events?
- From: Bing Li <email@hidden>
- Date: Mon, 06 Jun 2011 17:51:27 +0800
Dear all,
I got a weird phenomenon when using NSNotificationCenter. At the server end,
when a remote message is received, the following code is called to notify
relevant module to respond.
When a client initializes a TCP connection with the server, it just sends
only one message each time. After that, it disconnects the connection. After
each disconnection, the relevant memory must be released, including removing
the observers.
If the client connects the server for the 2nd time, two notifications are
posted even though only one message is sent from the client! For the 3rd
time, three notifications for just one message. … The server becomes normal
until it is restarted.
I felt weird about the phenomenon. It seems that the NSNotificationCenter
can memorize the previous or old events? So even though I attempt to post
just one event, the previous events are also posted with the new one? Is it
true? How to clear the previous events?
-(void)notifyMessageReceived:(NSString *)message
{
// In the log, the string, "NotifyMessageReceived", is shown only
once if the remote client sends just one message.
NSLog(@"NotifyMessageReceived");
// The lines are used to save message in a dictionary to transmit
with the notification
NSMutableDictionary *messageDictionary = [[[NSMutableDictionary
alloc] initWithCapacity:5] autorelease];
[messageDictionary setObject:message forKey:"RECEIVED_MESSAGE"];
// To my surprise, the line is invoked the same times as the times
the client initializes a connection even though the client just sends only
one message after each connection is initialized
[[NSNotificationCenter defaultCenter]
postNotificationName:"MESSAGE_RECEIVED" object:self
userInfo:messageDictionary];
}
Thanks so much!
Best regards,
Bing
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden