Prevent memory leaks when adding listeners
Check if the callback has already been added to the set before protecting it. Vice versa for unprotecting it when removing the listener.
This commit is contained in:
parent
7df2997ee7
commit
83869e2193
|
@ -49,13 +49,17 @@ public:
|
|||
}
|
||||
|
||||
void add_notification(JSObjectRef notification) {
|
||||
if (!m_notifications.count(notification)) {
|
||||
JSValueProtect(m_context, notification);
|
||||
m_notifications.insert(notification);
|
||||
}
|
||||
}
|
||||
void remove_notification(JSObjectRef notification) {
|
||||
if (m_notifications.count(notification)) {
|
||||
JSValueUnprotect(m_context, notification);
|
||||
m_notifications.erase(notification);
|
||||
}
|
||||
}
|
||||
void remove_all_notifications() {
|
||||
for (auto notification : m_notifications) {
|
||||
JSValueUnprotect(m_context, notification);
|
||||
|
|
Loading…
Reference in New Issue