Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is OCMapper thread-safe? #48

Open
jpage4500 opened this issue Apr 15, 2016 · 2 comments
Open

Is OCMapper thread-safe? #48

jpage4500 opened this issue Apr 15, 2016 · 2 comments

Comments

@jpage4500
Copy link

Hi,

I've been using OCMapper for several weeks now and I'm a big fan! While there's a few things I'd love to see improved - in general it was the best JSON <-> Object library I could find for iOS.

However, every once and a while I noticed my app is crashing and the stack trace points inside of OCMapper. It's very difficult to reproduce which makes the crash even worse in my mind.

But, my theory is that OCMapper isn't thread-safe. We have a thread pool handling responses from the server and OCMapper processes everything as a singleton.

Is this a known limitation? I can handle the results in a single thread to be safe as well but wanted to know if it's supposed to be thread-safe and the issue is elsewhere in my code.

@interface ObjectMapper()
@property (nonatomic, strong) NSMutableArray *commonDateFormaters;
@property (nonatomic, strong) NSMutableDictionary *mappedClassNames;
@property (nonatomic, strong) NSMutableDictionary *mappedPropertyNames;
@property (nonatomic, strong) NSMutableArray *instanceProviders;
@end
@aryaxt
Copy link
Owner

aryaxt commented Apr 19, 2016

Hi @jpage4500
I've never had any issues with threading. I'm using OCMapper in my current app that has 100k sessions, millions of HTTP requests a day. OCMapper is always running on the global queue. I'll write some tests and try to map object on as many threads as possible to be sure, but I doubt that threading is your issue.

Do you happen to have the crash logs?

@aryaxt
Copy link
Owner

aryaxt commented Apr 19, 2016

I have something similar to this

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
   guard let json = json else { 
      dispatch_async(dispatch_get_main_queue()) {
           completeWithError(NetworkErrorType.UnexpectedEmptyResponse) 
      }
      return
   }

   let convertedObject = ObjectMapper.sharedInstance().objectFromSource(json, toInstanceOfClass: type) as? T

   dispatch_async(dispatch_get_main_queue()) {
        completion(SingleNetworkResponse<T>(data: convertedObject, response: response))
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants