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

fixed the performselector method lead memory leak use nsInvocation re… #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Routable.xcodeproj/xcshareddata/xcschemes/Routable.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F86EF9E3170C3C7B00EB726A"
BuildableName = "RoutableTests.octest"
BuildableName = "RoutableTests.xctest"
BlueprintName = "RoutableTests"
ReferencedContainer = "container:Routable.xcodeproj">
</BuildableReference>
Expand All @@ -48,17 +48,21 @@
ReferencedContainer = "container:Routable.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F86EF9C3170C3C7B00EB726A"
Expand All @@ -71,12 +75,13 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F86EF9C3170C3C7B00EB726A"
Expand Down
32 changes: 26 additions & 6 deletions Routable/Routable.m
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,35 @@ - (UIViewController *)controllerForRouterParams:(RouterParams *)params {
SEL CONTROLLER_SELECTOR = sel_registerName("initWithRouterParams:");
UIViewController *controller = nil;
Class controllerClass = params.routerOptions.openClass;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if ([controllerClass respondsToSelector:CONTROLLER_CLASS_SELECTOR]) {
controller = [controllerClass performSelector:CONTROLLER_CLASS_SELECTOR withObject:[params controllerParams]];

/***
Fix by SerilesJam
this place use performselector will be cause leak and will be UIViewController instance can't excute -(void)dealloc
method. We replace the new method
***/

if ([controllerClass respondsToSelector:CONTROLLER_CLASS_SELECTOR]) {
NSMethodSignature *sig = [controllerClass methodSignatureForSelector:CONTROLLER_CLASS_SELECTOR];
NSInvocation *invocatin = [NSInvocation invocationWithMethodSignature:sig];
[invocatin setTarget:controllerClass];
[invocatin setSelector:CONTROLLER_CLASS_SELECTOR];
NSDictionary *paramsDic = [params controllerParams];
[invocatin setArgument:&paramsDic atIndex:2];
[invocatin invoke];
[invocatin getReturnValue: &controller];
}
else if ([params.routerOptions.openClass instancesRespondToSelector:CONTROLLER_SELECTOR]) {
controller = [[params.routerOptions.openClass alloc] performSelector:CONTROLLER_SELECTOR withObject:[params controllerParams]];
__kindof UIViewController *target = [controllerClass alloc];
NSMethodSignature *sig = [controllerClass instanceMethodSignatureForSelector:CONTROLLER_SELECTOR];
NSInvocation *invocatin = [NSInvocation invocationWithMethodSignature:sig];
[invocatin setTarget:target];
[invocatin setSelector:CONTROLLER_SELECTOR];
NSDictionary *paramsDic = [params controllerParams];
[invocatin setArgument:&paramsDic atIndex:2];
[invocatin invoke];
controller = target;
}
#pragma clang diagnostic pop
if (!controller) {
if (_ignoresExceptions) {
return controller;
Expand Down