# Gzip read() causing java heap error

**URL:** <https://forum.inductiveautomation.com/t/gzip-read-causing-java-heap-error/5575>\
**Category:** Ignition\
**Created:** [December 13, 2012, 6:39pm UTC](https://forum.inductiveautomation.com/t/gzip-read-causing-java-heap-error/5575 "2012-12-13T18:39:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [December 13, 2012, 6:39pm UTC](https://forum.inductiveautomation.com/t/gzip-read-causing-java-heap-error/5575/1 "2012-12-13T18:39:36Z")

</div>

I have a user who is having a java heap problem when running a scripted button that downloads a gz file off an FTP site and then unzips the file.

we have been using the screen for several years now, but the downloaded file has grown. the file is currently 124 MB and is a csv file that contains ~668,000 lines.

i have the client set to an initial memory of 512MB and a max memory of 1024MB. if i try changing the max to 2048 the client will not launch.

is there something i can do so the client does not run out of memory unzipping the file?

here is the snippet of code

```auto
	import java
	import org.python.core
	import gzip
	import java.lang.StringBuffer as SB
	
	gzipFile = gzip.open(filename) #open read-binary file f with name fn
	contents = gzipFile.read() #THIS IS LINE 51
	gzipFile.close()
	
	print "file unzipped"
```

> [@](#):
>
> Traceback (most recent call last):  
> File "event:actionPerformed", line 51, in runThread  
> File "C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script\_lib2\Lib\gzip.py", line 224, in read  
> self.\_read(readsize)  
> File "C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script\_lib2\Lib\gzip.py", line 224, in read  
> self.\_read(readsize)  
> File "C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script\_lib2\Lib\gzip.py", line 284, in \_read  
> self.\_add\_read\_data( uncompress )  
> File "C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script\_lib2\Lib\gzip.py", line 301, in \_add\_read\_data  
> self.extrabuf = self.extrabuf + data  
> java.lang.OutOfMemoryError: Java heap space
> 
> ```
> at java.lang.String.concat(Unknown Source)
> 
> at org.python.core.PyString.str ___add__ (PyString.java:741)
> 
> at org.python.core.PyString. __add__ (PyString.java:731)
> 
> at org.python.core.PyObject._basic_add(PyObject.java:2009)
> 
> at org.python.core.PyObject._add(PyObject.java:1995)
> 
> at gzip$py._add_read_data$18(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script_lib2\Lib\gzip.py:303)
> 
> at gzip$py.call_function(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script_lib2\Lib\gzip.py)
> 
> at org.python.core.PyTableCode.call(PyTableCode.java:165)
> 
> at org.python.core.PyBaseCode.call(PyBaseCode.java:149)
> 
> at org.python.core.PyFunction. __call__ (PyFunction.java:327)
> 
> at org.python.core.PyMethod. __call__ (PyMethod.java:124)
> 
> at gzip$py._read$17(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script_lib2\Lib\gzip.py:297)
> 
> at gzip$py.call_function(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script_lib2\Lib\gzip.py)
> 
> at org.python.core.PyTableCode.call(PyTableCode.java:165)
> 
> at org.python.core.PyBaseCode.call(PyBaseCode.java:149)
> 
> at org.python.core.PyFunction. __call__ (PyFunction.java:327)
> 
> at org.python.core.PyMethod. __call__ (PyMethod.java:124)
> 
> at gzip$py.read$15(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script_lib2\Lib\gzip.py:242)
> 
> at gzip$py.call_function(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script_lib2\Lib\gzip.py)
> 
> at org.python.core.PyTableCode.call(PyTableCode.java:165)
> 
> at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
> 
> at org.python.core.PyBaseCode.call(PyBaseCode.java:127)
> 
> at org.python.core.PyFunction. __call__ (PyFunction.java:317)
> 
> at org.python.core.PyMethod. __call__ (PyMethod.java:109)
> 
> at org.python.pycode._pyx36.runThread$1(<event:actionPerformed>:124)
> 
> at org.python.pycode._pyx36.call_function(<event:actionPerformed>)
> 
> at org.python.core.PyTableCode.call(PyTableCode.java:165)
> 
> at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
> 
> at org.python.core.PyBaseCode.call(PyBaseCode.java:114)
> 
> at org.python.core.PyFunction. __call__ (PyFunction.java:307)
> 
> at org.python.core.PyFunction. __call__ (PyFunction.java:302)
> 
> at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:551)
> 
> ```
> 
> java.lang.OutOfMemoryError: java.lang.OutOfMemoryError: Java heap space
> 
> ```
> at org.python.core.PyException.fillInStackTrace(PyException.java:70)
> at java.lang.Throwable.<init>(Throwable.java:181)
> at java.lang.Exception.<init>(Unknown Source)
> at java.lang.RuntimeException.<init>(Unknown Source)
> at org.python.core.PyException.<init>(PyException.java:46)
> at org.python.core.PyException.<init>(PyException.java:43)
> at org.python.core.Py.JavaError(Py.java:481)
> at org.python.core.PyTableCode.call(PyTableCode.java:168)
> at org.python.core.PyBaseCode.call(PyBaseCode.java:149)
> at org.python.core.PyFunction. __call__ (PyFunction.java:327)
> at org.python.core.PyMethod. __call__ (PyMethod.java:124)
> at gzip$py._read$17(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script_lib2\Lib\gzip.py:297)
> at gzip$py.call_function(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script_lib2\Lib\gzip.py)
> at org.python.core.PyTableCode.call(PyTableCode.java:165)
> at org.python.core.PyBaseCode.call(PyBaseCode.java:149)
> at org.python.core.PyFunction. __call__ (PyFunction.java:327)
> at org.python.core.PyMethod. __call__ (PyMethod.java:124)
> at gzip$py.read$15(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script_lib2\Lib\gzip.py:242)
> at gzip$py.call_function(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script_lib2\Lib\gzip.py)
> at org.python.core.PyTableCode.call(PyTableCode.java:165)
> at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
> at org.python.core.PyBaseCode.call(PyBaseCode.java:127)
> at org.python.core.PyFunction. __call__ (PyFunction.java:317)
> at org.python.core.PyMethod. __call__ (PyMethod.java:109)
> at org.python.pycode._pyx36.runThread$1(<event:actionPerformed>:124)
> at org.python.pycode._pyx36.call_function(<event:actionPerformed>)
> at org.python.core.PyTableCode.call(PyTableCode.java:165)
> at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
> at org.python.core.PyBaseCode.call(PyBaseCode.java:114)
> at org.python.core.PyFunction. __call__ (PyFunction.java:307)
> at org.python.core.PyFunction. __call__ (PyFunction.java:302)
> at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:551)
> at com.inductiveautomation.factorypmi.application.script.builtin.ClientSystemUtilities$3.run(ClientSystemUtilities.java:306)
> at java.lang.Thread.run(Unknown Source)
> 
> ```
> 
> Caused by: java.lang.OutOfMemoryError: Java heap space  
> at java.lang.String.concat(Unknown Source)  
> at org.python.core.PyString.str\_\_\_add\_\_(PyString.java:741)  
> at org.python.core.PyString. **add** (PyString.java:731)  
> at org.python.core.PyObject.\_basic\_add(PyObject.java:2009)  
> at org.python.core.PyObject.\_add(PyObject.java:1995)  
> at gzip$py.\_add\_read\_data$18(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script\_lib2\Lib\gzip.py:303)  
> at gzip$py.call\_function(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script\_lib2\Lib\gzip.py)  
> at org.python.core.PyTableCode.call(PyTableCode.java:165)  
> at org.python.core.PyBaseCode.call(PyBaseCode.java:149)  
> at org.python.core.PyFunction. **call** (PyFunction.java:327)  
> at org.python.core.PyMethod. **call** (PyMethod.java:124)  
> at gzip$py.\_read$17(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script\_lib2\Lib\gzip.py:297)  
> at gzip$py.call\_function(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script\_lib2\Lib\gzip.py)  
> at org.python.core.PyTableCode.call(PyTableCode.java:165)  
> at org.python.core.PyBaseCode.call(PyBaseCode.java:149)  
> at org.python.core.PyFunction. **call** (PyFunction.java:327)  
> at org.python.core.PyMethod. **call** (PyMethod.java:124)  
> at gzip$py.read$15(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script\_lib2\Lib\gzip.py:242)  
> at gzip$py.call\_function(C:\Users\rhonda.SIERRANEVADA\AppData\LocalLow\Sun\Java\Deployment\cache\FPMI\script\_lib2\Lib\gzip.py)  
> at org.python.core.PyTableCode.call(PyTableCode.java:165)  
> at org.python.core.PyBaseCode.call(PyBaseCode.java:301)  
> at org.python.core.PyBaseCode.call(PyBaseCode.java:127)  
> at org.python.core.PyFunction. **call** (PyFunction.java:317)  
> at org.python.core.PyMethod. **call** (PyMethod.java:109)  
> at org.python.pycode.\_pyx36.runThread$1(event:actionPerformed:124)  
> at org.python.pycode.\_pyx36.call\_function(event:actionPerformed)  
> at org.python.core.PyTableCode.call(PyTableCode.java:165)  
> at org.python.core.PyBaseCode.call(PyBaseCode.java:301)  
> at org.python.core.PyBaseCode.call(PyBaseCode.java:114)  
> at org.python.core.PyFunction. **call** (PyFunction.java:307)  
> at org.python.core.PyFunction. **call** (PyFunction.java:302)  
> at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:551)
> 
> Ignition v7.5.3 (b1163)  
> Java: Sun Microsystems Inc. 1.6.0\_30

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [December 13, 2012, 7:04pm UTC](https://forum.inductiveautomation.com/t/gzip-read-causing-java-heap-error/5575/2 "2012-12-13T19:04:04Z")

</div>

If you launch the client using a 64-bit version of Java you should be able to increase the memory to 2048. It won’t launch on a 32-bit Java since it has a max of 1024 MB of memory. Does it work if you use a 64-bit version of Java or do you get the same problem?

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [December 13, 2012, 8:16pm UTC](https://forum.inductiveautomation.com/t/gzip-read-causing-java-heap-error/5575/3 "2012-12-13T20:16:10Z")

</div>

it works on my 64-bit version of java.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [December 13, 2012, 9:36pm UTC](https://forum.inductiveautomation.com/t/gzip-read-causing-java-heap-error/5575/4 "2012-12-13T21:36:21Z")

</div>

Well it seems there is a memory issue with Jython when using gzip. You can try putting this code before your script runs to see if it helps:`from java.lang import System
System.setProperty("python.options.internalTablesImpl","weak")`Run it on a 32-bit Java and let me know.
