Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Java] BugReport... java.lang.OutOfMemoryError: ... Durch IPConnection

Featured Replies

Geschrieben

Hab da glaub ich ein Thread-Alloc no De-Alloc Problem gefunden:

 

Folgender Testcase:

while (true){
try{
IPConnection ipConnection = new IPConnection();
ipConnection.connect("host_den_es_nicht_gibt",4223);
}catch(Exception ex){
  //Hier wirds immer wieder rein kommen, da UnknownHostException
}
}

Das wird ziemlich schnell zu einem MemoryError führen. Grund ist hier:

// NOTE: Assumes that socket is null and socketMutex is locked
void connectUnlocked(boolean isAutoReconnect) throws java.net.UnknownHostException,
                                                     java.io.IOException {
	if(callbackThread == null) {
		callbackQueue = new LinkedBlockingQueue<CallbackQueueObject>();
		callbackThread = new CallbackThread(this, callbackQueue);
		callbackThread.start();
	}

	Socket tmpSocket = new Socket(host, port);
...

 

Nachdem der callbackThread gestartet wurde, wird ein Socket erstellt und der wirft eine Exception und die Methode wird verlassen... Der Thread aber... der läuft !jeweils! weiter.

 

Vorschlag auf die Schnelle:

 

// NOTE: Assumes that socket is null and socketMutex is locked
void connectUnlocked(boolean isAutoReconnect) throws java.net.UnknownHostException,
                                                     java.io.IOException {
try{
	if(callbackThread == null) {
		callbackQueue = new LinkedBlockingQueue<CallbackQueueObject>();
		callbackThread = new CallbackThread(this, callbackQueue);
		callbackThread.start();
	}

	Socket tmpSocket = new Socket(host, port);
...
}catch(Exception ex){
   callbackQueue.put(new CallbackQueueObject(QUEUE_EXIT, (byte)0,(short)0,0, null));
   throw ex;
}

 

 

  • 2 weeks later...
  • 3 months later...
Geschrieben
  • Autor

Ou, da hab ich einen Task übersehen, der an mich gegangen ist...

 

Was ich weiss: In den 2.1.13 Bindings ist der Memory-Fresser noch drin.

(Mit dem Beispielprogramm, von oben frisst der Java-Prozess pro Sekunde etwa 500kB)

Aber das ist vielleicht, weil ich hier nie geantwortet habe. Soll ich das hier angehängte noch testen? Es scheint mir, als ob das mit dem 2.1.13 bzgl. aufräument im connect() ziemlich übereinstimmt.

 

 

Geschrieben
  • Autor

Moment... ich habe mit den falschen Bindings getestet... Ich werde das noch einmal für 2.1.13 machen...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.