# Loading a 100MB PNG and draw it on the canvas but it eats 1GB of RAM :(

**URL:** https://discourse.processing.org/t/loading-a-100mb-png-and-draw-it-on-the-canvas-but-it-eats-1gb-of-ram/37791
**Category:** Coding Questions
**Tags:** homework
**Created:** [July 1, 2022, 8:26pm UTC](https://discourse.processing.org/t/loading-a-100mb-png-and-draw-it-on-the-canvas-but-it-eats-1gb-of-ram/37791 "2022-07-01T20:26:17Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [July 7, 2022, 11:00am UTC](https://discourse.processing.org/t/loading-a-100mb-png-and-draw-it-on-the-canvas-but-it-eats-1gb-of-ram/37791/3 "2022-07-07T11:00:43Z")

</div>

Hello,

There are tools that you can use to monitor memory usage such as VisualVM:  
[https://visualvm.github.io/](https://visualvm.github.io/)

I found this Java.lang.Runtime class useful to monitor memory usage:

> **[Java.lang.Runtime class in Java - GeeksforGeeks](https://www.geeksforgeeks.org/java-lang-runtime-class-in-java/)**
>
> A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

I created a couple of images in different formats (JPG and PNG) that were 15000x7000 in image size in pixels which is not the same as image size of the file.

The image size of the file is in the comments in the code below and here:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/3/a/3ac2512a69e797be9fea41a9bddefa886284cae3.png)

Results:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/2/1/21dcfd7189689e10e1552732cf046678893be205.png)

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/5/85b23742397e815e1775a20e0680e4f248b88625.png)

The size in memory is the same and it makes no difference if it is a JPG or PNG file.

I did NOT check this and set a size in _Preferences_ for testing:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/b/1be3c9e7a1900c5a894d35a26dbfda8d139b0aba.png)

If you do set the _ **maximum available memory** _ give consideration to memory usage for your program and how much memory you have on your system.

I have 16GB and had memory available.

References:

> **[Reference](https://processing.org/reference/color_datatype.html)**
>
> Datatype for storing color values. Colors may be assigned with get() and color() or they may be specified directly using hexadecimal notation such as #FFCC00 or 0xFFFFCC00.…

`:)`

---

_[View the full topic](https://discourse.processing.org/t/loading-a-100mb-png-and-draw-it-on-the-canvas-but-it-eats-1gb-of-ram/37791)._
