{"action":"created","issue":{"url":"https://api.github.com/repos/yapstudios/YapDatabase/issues/332","repository_url":"https://api.github.com/repos/yapstudios/YapDatabase","labels_url":"https://api.github.com/repos/yapstudios/YapDatabase/issues/332/labels{/name}","comments_url":"https://api.github.com/repos/yapstudios/YapDatabase/issues/332/comments","events_url":"https://api.github.com/repos/yapstudios/YapDatabase/issues/332/events","html_url":"https://github.com/yapstudios/YapDatabase/issues/332","id":158808486,"number":332,"title":"YapDatabaseActionManager leaks and memory corruption","user":{"login":"skeeet","id":632777,"avatar_url":"https://avatars.githubusercontent.com/u/632777?v=3","gravatar_id":"","url":"https://api.github.com/users/skeeet","html_url":"https://github.com/skeeet","followers_url":"https://api.github.com/users/skeeet/followers","following_url":"https://api.github.com/users/skeeet/following{/other_user}","gists_url":"https://api.github.com/users/skeeet/gists{/gist_id}","starred_url":"https://api.github.com/users/skeeet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skeeet/subscriptions","organizations_url":"https://api.github.com/users/skeeet/orgs","repos_url":"https://api.github.com/users/skeeet/repos","events_url":"https://api.github.com/users/skeeet/events{/privacy}","received_events_url":"https://api.github.com/users/skeeet/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-06-07T01:06:38Z","updated_at":"2016-06-08T16:53:28Z","closed_at":"2016-06-08T16:49:57Z","body":"There are two issues in action manager:\r\n1 - YapDatabaseActionManager creating internal connection, and never releasing it. So any attempts to close database instance will cause a leak.\r\nHere is a simple way to reproduce.\r\n``` \r\n- (void)setupDatabase\r\n{\r\n\tNSString *databasePath = [self databasePath];\r\n\t\r\n\t[[NSFileManager defaultManager] removeItemAtPath:databasePath error:NULL];\r\n\t\r\n\tDDLogVerbose(@\"Creating database instance...\");\r\n\tdatabase = [[YapDatabase alloc] initWithPath:databasePath];\r\n    \r\n    YapDatabaseViewOptions * amOpts = [[YapDatabaseViewOptions alloc] init];\r\n    amOpts.isPersistent = YES;\r\n    YapDatabaseActionManager * actionManager = [[YapDatabaseActionManager alloc] initWithOptions:amOpts];\r\n    if (![database registerExtension:actionManager withName:@\"actionManager\"]) {\r\n        DDLogError(@\"Unable to register extension: actionManager\");\r\n    }\r\n    \r\n    //retain cycle\r\ndispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{\r\n        database = nil;\r\n    });\r\n    \r\n    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onYapDatabaseClosed:) name:YapDatabaseClosedNotification object:nil];\r\n\r\n    //memory corruption\r\n    // [database unregisterExtensionWithName:@\"actionManager\"]; //will cause same crash\r\n    \r\n}\r\n\r\n-(void)onYapDatabaseClosed:(NSNotification*)note\r\n{\r\n    //never called\r\n}\r\n```\r\n2 - Even if connection is not retained (in my case, connection provided in constructor/subclass), any attempts to close database will cause crash, similar to #303 / #307\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/yapstudios/YapDatabase/issues/comments/224655282","html_url":"https://github.com/yapstudios/YapDatabase/issues/332#issuecomment-224655282","issue_url":"https://api.github.com/repos/yapstudios/YapDatabase/issues/332","id":224655282,"user":{"login":"robbiehanson","id":304604,"avatar_url":"https://avatars.githubusercontent.com/u/304604?v=3","gravatar_id":"","url":"https://api.github.com/users/robbiehanson","html_url":"https://github.com/robbiehanson","followers_url":"https://api.github.com/users/robbiehanson/followers","following_url":"https://api.github.com/users/robbiehanson/following{/other_user}","gists_url":"https://api.github.com/users/robbiehanson/gists{/gist_id}","starred_url":"https://api.github.com/users/robbiehanson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robbiehanson/subscriptions","organizations_url":"https://api.github.com/users/robbiehanson/orgs","repos_url":"https://api.github.com/users/robbiehanson/repos","events_url":"https://api.github.com/users/robbiehanson/events{/privacy}","received_events_url":"https://api.github.com/users/robbiehanson/received_events","type":"User","site_admin":false},"created_at":"2016-06-08T16:53:28Z","updated_at":"2016-06-08T16:53:28Z","body":"> in my case, connection provided in constructor/subclass\r\n\r\nThis is a good idea. I'd happily accept a pull request for this too."}}
{"actor":{"display_login":"robbiehanson"}}