{"action":"created","issue":{"url":"https://api.github.com/repos/excilys/androidannotations/issues/1745","repository_url":"https://api.github.com/repos/excilys/androidannotations","labels_url":"https://api.github.com/repos/excilys/androidannotations/issues/1745/labels{/name}","comments_url":"https://api.github.com/repos/excilys/androidannotations/issues/1745/comments","events_url":"https://api.github.com/repos/excilys/androidannotations/issues/1745/events","html_url":"https://github.com/excilys/androidannotations/issues/1745","id":147120051,"number":1745,"title":"OnViewChangedNotifier possible memory leak","user":{"login":"mniami","id":14277853,"avatar_url":"https://avatars.githubusercontent.com/u/14277853?v=3","gravatar_id":"","url":"https://api.github.com/users/mniami","html_url":"https://github.com/mniami","followers_url":"https://api.github.com/users/mniami/followers","following_url":"https://api.github.com/users/mniami/following{/other_user}","gists_url":"https://api.github.com/users/mniami/gists{/gist_id}","starred_url":"https://api.github.com/users/mniami/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mniami/subscriptions","organizations_url":"https://api.github.com/users/mniami/orgs","repos_url":"https://api.github.com/users/mniami/repos","events_url":"https://api.github.com/users/mniami/events{/privacy}","received_events_url":"https://api.github.com/users/mniami/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-09T11:16:03Z","updated_at":"2016-04-16T14:52:02Z","closed_at":null,"body":"Hi guys, \r\n\r\nI can see in my class that OnViewChangedNotifier could cause memory leak. \r\nregisterOnViewChangedListener() method is called in any EBean class with parameter \"this\" but never unregister.\r\nThat's for me serious memory issue. \r\n\r\n```java\r\npublic static OnViewChangedNotifier replaceNotifier(OnViewChangedNotifier notifier) {\r\n\t\tOnViewChangedNotifier previousNotifier = currentNotifier;\r\n\t\tcurrentNotifier = notifier;\r\n\t\treturn previousNotifier;\r\n\t}\r\npublic static void registerOnViewChangedListener(OnViewChangedListener listener) {\r\n\t\tif (currentNotifier != null) {\r\n\t\t\tcurrentNotifier.listeners.add(listener);\r\n\t\t}\r\n\t}\r\n```\r\nMy proposition is to add sth like that\r\n```java\r\npublic static OnViewChangedNotifier replaceNotifier(OnViewChangedNotifier notifier) {\r\n\t\tOnViewChangedNotifier previousNotifier = currentNotifier;\r\nif (previousNotifier != null){ previouseNotifier.listeners.clear(); }\r\n\t\tcurrentNotifier = notifier;\r\n\t\treturn previousNotifier;\r\n\t}\r\n```\r\n\r\nPlease consider to change it in later version.\r\n\r\nBest regards Damian."},"comment":{"url":"https://api.github.com/repos/excilys/androidannotations/issues/comments/210834037","html_url":"https://github.com/excilys/androidannotations/issues/1745#issuecomment-210834037","issue_url":"https://api.github.com/repos/excilys/androidannotations/issues/1745","id":210834037,"user":{"login":"WonderCsabo","id":480485,"avatar_url":"https://avatars.githubusercontent.com/u/480485?v=3","gravatar_id":"","url":"https://api.github.com/users/WonderCsabo","html_url":"https://github.com/WonderCsabo","followers_url":"https://api.github.com/users/WonderCsabo/followers","following_url":"https://api.github.com/users/WonderCsabo/following{/other_user}","gists_url":"https://api.github.com/users/WonderCsabo/gists{/gist_id}","starred_url":"https://api.github.com/users/WonderCsabo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WonderCsabo/subscriptions","organizations_url":"https://api.github.com/users/WonderCsabo/orgs","repos_url":"https://api.github.com/users/WonderCsabo/repos","events_url":"https://api.github.com/users/WonderCsabo/events{/privacy}","received_events_url":"https://api.github.com/users/WonderCsabo/received_events","type":"User","site_admin":false},"created_at":"2016-04-16T14:52:02Z","updated_at":"2016-04-16T14:52:02Z","body":"@mniami i just checked and this is not a problem. When the `Activity` / `Fragment` is (re)created, its notifier is also reset, so the old listeners will be eligible for garbage collection."}}