react-native-webrtc / react-native-webrtc/react-native-callkeep
Concerns about init not being called, and allocWithZone being misused as a singleton, in the iOS Obj-c code
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 511
- Avg merge
- 9h 12m
- Merged PRs (30d)
- 2
Description
Hi all,
I've been trying to delve into RNCallKeep to understand some things, and came across this which I thought might be worth bringing to your attention:
- In
setup, it calls 'alloc' but does not 'init'. - This is not the way things are done in Obj-C, according to Apple "You must use an init... method to complete the initialization process": https://developer.apple.com/documentation/objectivec/nsobject/1571958-alloc
- allocWithZone is just there for historical reasons, idiomatically this is not to be called, alloc is what should be called.
Delving further, it appears someone has overridden allocWithZone to implement a singleton:
- This is confusing and un-idiomatic: allowWithZone isn't to be used, alloc is
- Also alloc is about allocating new memory, not about managing singletons.
May I suggest a more idiomatic way to implement a singleton in objc is the following:
+ (instancetype)sharedInstance {
static MySingleton *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
Please note the importance of calling 'init' in the above singleton.
I did place a breakpoint in 'init' but just got a callstack of incomprehensible RN C++ - I don't know what's calling this, and it concerns me that this is not being done properly.
Any chance that this could be improved? I could raise a PR but if so i'd love the feedback of the authors as to how this is (or if it is?) actually being inited currently and how to fix that too, or we might end up initing twice somehow.
Thanks all :)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in ios/RNCallKeep/RNCallKeep.m at setup and the allocWithZone override linked in the issue. Trace the initialization path and singleton usage, then confirm the intended lifecycle with the authors; done means the initialization behavior and singleton implementation are idiomatic and do not initialize the instance twice.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- objective-c, react-native
- Domain
- mobile-dev
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100