Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutOfMemoryError in Jsoup.connect().get()

Trying connect to some sites with Jsoup on Android, and it throws java.lang.OutOfMemoryError exception. Example:

Jsoup.connect("http://www.xbox360achievements.org/game/grand-theft-auto-iv/guide/").get();

What could be done to avoid this problem?

Jsoup 1.7.1

like image 683
pmiguelpinto Avatar asked Mar 28 '26 08:03

pmiguelpinto


1 Answers

An OutOfMemoryError means that your application is using more memory than is available to it. (Duh!)

Your options are:

  • Increase the amount of memory that the app is allowed to use.

  • Decrease the amount of memory that the app does use. For instance:

    • Don't read and buffer the entire document before parsing it with jsoup.

    • Make sure that you are not keeping too much information in memory from the pages you are crawling. Either write it to the file system, or "reduce" it on the fly.

    • Profile the app's memory usage to look for leaks and other problems with excessive memory use.

like image 173
Stephen C Avatar answered Mar 29 '26 20:03

Stephen C