Skip to content

Instantly share code, notes, and snippets.

@colinta
Last active August 29, 2015 13:55
Show Gist options
  • Save colinta/8693724 to your computer and use it in GitHub Desktop.
Save colinta/8693724 to your computer and use it in GitHub Desktop.
Hash.new memory leak
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
first = UINavigationController.alloc.initWithRootViewController(RootController.new)
first.pushViewController(TestController.new, animated: false)
first.pushViewController(TestController.new, animated: false)
first.pushViewController(WorkingController.new, animated: false)
@window.rootViewController = first
@window.makeKeyAndVisible
true
end
end
class RootController < UIViewController
end
class WorkingController < UIViewController
def viewDidLoad
puts "loaded WorkingController"
@hash = Hash.new(0)
end
def viewDidAppear(animated)
self.navigationController.popViewControllerAnimated(true)
end
def dealloc
puts "dealloc WorkingController"
super
end
end
class TestController < UIViewController
def viewDidLoad
puts "loaded TestController"
@hash = Hash.new do |hash,key|
hash[key] = 0
end
end
def viewDidAppear(animated)
self.navigationController.popViewControllerAnimated(true)
end
def dealloc
puts "dealloc TestController"
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment