-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Out of memory exception on Android while trying to reconnect #51
Comments
Probably a duplicate of #48 |
i merge the commit to my code,still OOM,how can i solve this problem? can you help me? |
Maybe you are trying to connect to the server repeated while it is already connected to server. private void connect() {
//AndroidUtils.checkNotMain();
// 连接服务器
if (isConnected()) {
return;
}
mCallbackConnection = mMQTT.callbackConnection();
mCallbackConnection.listener(new ExtendedListener() {
@Override public void onConnected() {
mConnected = true;
}
@Override public void onDisconnected() {
mConnected = false;
}
...
}
}
private boolean isConnected() {
return mConnected;
} Now it's ok, no OOM. But i got another problem ,somtimes it will crash:
|
The commit #48 & #51,This line has been changed , like this: THKS. |
@zhlmgithub void handleSessionFailure(Throwable error) {
// Socket failure, should we try to reconnect?
if (!disconnected && (mqtt.reconnectAttemptsMax < 0
|| reconnects < mqtt.reconnectAttemptsMax)) {
mqtt.tracer.debug("Reconnecting transport");
// Cleanup the previous transport.
if (heartBeatMonitor != null) {
heartBeatMonitor.stop();
heartBeatMonitor = null;
}
final Transport t = transport;
transport = null;
if (t != null) {
t.stop(new Task() {
@Override public void run() {
listener.onDisconnected();
reconnect();
}
});
} else {
reconnect();
}
} else {
// nope.
handleFatalFailure(error);
}
} |
This is my code:
I launch the app and client successfully connects.
Then I switch wifi off and on and wait until the client reconnects. After repeating this 2-3 times mqttclient starts opening and closing connections like crazy until the app crashes with OutOfMemoryError:
and here is what happens in mosquitto logs:
The text was updated successfully, but these errors were encountered: