From 4ff79d24d7f1d73b3e34acefcfdd411cb83902c0 Mon Sep 17 00:00:00 2001 From: Jumper Chen Date: Fri, 31 Jul 2020 14:46:44 +0800 Subject: [PATCH] Resolve #108 Need dispose method for clearing resources --- CHANGELOG.md | 6 ++++++ README.md | 3 +++ lib/src/socket.dart | 10 ++++++++++ pubspec.yaml | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4e6971..b4d1f52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.9.11 + +**New Feature:** + +* [#108](https://github.com/rikulo/socket.io-client-dart/issues/108) Need dispose method for clearing resources + ## 0.9.10+2 * Fix dart analyzer warning for formatting issues. diff --git a/README.md b/README.md index 6586c39..bc6ab60 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,9 @@ void main() { } ``` +### Memory leak issues in iOS when closing socket. +* Refer to https://github.com/rikulo/socket.io-client-dart/issues/108 issue. +Please use `socket.dispose()` instead of `socket.close()` or `socket.disconnect()` to solve the memory leak issue on iOS. ## Notes to Contributors diff --git a/lib/src/socket.dart b/lib/src/socket.dart index 09c9b6d..d5bbaaa 100644 --- a/lib/src/socket.dart +++ b/lib/src/socket.dart @@ -407,6 +407,16 @@ class Socket extends EventEmitter { return this; } + /// Disposes the socket manually which will destroy, close, disconnect the socket connection + /// and clear all the event listeners. Unlike [close] or [disconnect] which won't clear + /// all the event listeners + /// + /// @since 0.9.11 + void dispose() { + disconnect(); + clearListeners(); + } + /// /// Sets the compress flag. /// diff --git a/pubspec.yaml b/pubspec.yaml index 9ebb05c..4ceb956 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: socket_io_client description: Dartlang port of socket.io-client for web, flutter, dartvm to use -version: 0.9.10+2 +version: 0.9.11 homepage: https://www.zkoss.org repository: https://github.com/rikulo/socket.io-client-dart issue_tracker: https://github.com/rikulo/socket.io-client-dart/issues