Out of memory error

Hi,

I implemented a screenshot in my app with the captureOffScreenArea.

However, during my test, when the image got really big, I had an “Out of memory error” error.

So, I turned largeHeap to true and it now seems to work fine.

Nevertheless, I’m a bit scared of the behaviour of this screenshot once I will have published the app…

Could this “Out of memory error” still occur even though I’ve turned largeHeap to true?

Thanks in advance for your replies

It may still be possible for you to encounter that error. The documentation states that large heapmay raise the max heap size on a particular device from 32 MB to 256 MB”.

This means that whether or not you will encounter that area is entirely dependent on if the heap size is raised to 256 MB and if your capture area requires less than or equal to 256 MB of texture memory.

If you aren’t familiar with texture memory, you should google it. Basically, the texture memory used is “width x heigth x 4 / 1024 / 1024” where width and height abide by power of two values. If your screen capture’s area is 1000 wide and 1030 pixels high, then the texture memory used would be 1024 x 2048 x 4 / 1024 / 1024 = 8 (MB). This would mean that if the area that you are capturing were to reach the size of 4097 x 4097, you’d reach that 256 MB texture memory limit from a single screen capture.

I am quite sure that I’ve read somewhere that Google has specifically recommended that developers should try to avoid toggling large heap unless absolutely necessary.

Hi, thank you very much for your very informative reply!

In fact, in the app, I need to save a table “outside” the app to make sure users can access it at any time.

So, I thought I could display my table with all information in it and then make a screenshot so that they have it saved in photos library.

But now that I’ve encountered this problem, I think it’s not a really good idea…

So maybe I could divide my table into several pieces?

Or would you know any other possibility, less memory-consuming?

If you need to use the screen capture method, then I would recommend that you keep everything that you need to capture within the screen bounds.

In my apps, if I want to capture a screenshot or snapshot of something, but I don’t want the user seeing it on their screen, I simply create a display group behind my background group, which usually consists of a single rect or image rect that covers the entire screen.

I tried your method but when my table gets really big, the image’s quality gets really bad…

I don’t use captureOffScreenArea to hide it from the user’s view but because if there’s a lot of data, I want to keep a good quality.

Basically, I’ve got a lot of data with dates and other things and I want to create a table with it, then make a screenshot to export it to the users’ photo gallery so that they can keep it and do whatever they want with it.

I could maybe export a json file with the data but it would be less easy for users.

Not knowing anything about what kind of app you are working on or what sort of information might be on the table, I can’t really provide any valuable ideas.

Is starting the app and seeing everything that way too cumbersome or slow? Is there any reason why the user might not be able to access the table using the app at some point? If there is some online authentication, you could add an option to save offline views of some tables on the device. An app takes a few seconds to load, whereas it can easily take me upwards of 10 seconds to get to my photos and opening the correct one.

Have you carefully considered if it is even necessary to take the data outside of the app as an image or is this a “it’d be cool if” kind of idea? I get ideas like that very often, but in a situation like this, that idea might not be worth implementing  :wink:

In fact, I’m working on an app to help students organise themselves in their revisions. The app is now finished, tested… and everything seems to work fine.

However someone told me it was quite tricky to create this kind of app as, in case of problem with the app, I would be partly responsible for a potential exam failure… Therefore, I thought I could maybe save the data outside the app itself so that users can access it whatever happens to the app. Here is how this idea came to me.

If you are worried about potential trouble resulting from possible exam failures, I’d include a clause in the app’s terms of service where you explicitly state that the app is only meant to aid in the revision process and that you, i.e. the app developer and service provider, will not be responsible for any failed exams, etc.

There are many ways you can export your data to other formats, taking a picture is the worst of them. the user will need to pinch zoom, etc to see all data if table is larger than screen, it will be a pain to use.

why not just have an export button, ou email button, you can create a simple html table and send it by email. that way the user will always have his table in their email account, they can flag it and will be pretty easy to access it. The bonus with this approach is that the user can use the data to anything he wants, like using with other programs like excel.

saying this, @Xedur gave the best answer i can think of. I was going to tell you the same thing (with worst english).

Hi,

Thank you very much for your replies.

So I should convert my lua table into an html table?

html table;

cvs;

plain txt;

anything is better than screenshot.

if you go html:

https://getbootstrap.com/docs/4.0/content/tables/

https://www.w3schools.com/howto/howto_css_table_responsive.asp

Hi,

I firstly wanted to create a text file. But I needed, for users’ convenience, to save it somewhere they could access without using the app. And as this is not possible on ios I wanted to know if I could, using display.capture, make a screenshot and update it.

In fact, I would like the previous screenshot to be deleted in photo library and replaced by the new one.

Is this possible?

It may still be possible for you to encounter that error. The documentation states that large heapmay raise the max heap size on a particular device from 32 MB to 256 MB”.

This means that whether or not you will encounter that area is entirely dependent on if the heap size is raised to 256 MB and if your capture area requires less than or equal to 256 MB of texture memory.

If you aren’t familiar with texture memory, you should google it. Basically, the texture memory used is “width x heigth x 4 / 1024 / 1024” where width and height abide by power of two values. If your screen capture’s area is 1000 wide and 1030 pixels high, then the texture memory used would be 1024 x 2048 x 4 / 1024 / 1024 = 8 (MB). This would mean that if the area that you are capturing were to reach the size of 4097 x 4097, you’d reach that 256 MB texture memory limit from a single screen capture.

I am quite sure that I’ve read somewhere that Google has specifically recommended that developers should try to avoid toggling large heap unless absolutely necessary.

Hi, thank you very much for your very informative reply!

In fact, in the app, I need to save a table “outside” the app to make sure users can access it at any time.

So, I thought I could display my table with all information in it and then make a screenshot so that they have it saved in photos library.

But now that I’ve encountered this problem, I think it’s not a really good idea…

So maybe I could divide my table into several pieces?

Or would you know any other possibility, less memory-consuming?

If you need to use the screen capture method, then I would recommend that you keep everything that you need to capture within the screen bounds.

In my apps, if I want to capture a screenshot or snapshot of something, but I don’t want the user seeing it on their screen, I simply create a display group behind my background group, which usually consists of a single rect or image rect that covers the entire screen.

I tried your method but when my table gets really big, the image’s quality gets really bad…

I don’t use captureOffScreenArea to hide it from the user’s view but because if there’s a lot of data, I want to keep a good quality.

Basically, I’ve got a lot of data with dates and other things and I want to create a table with it, then make a screenshot to export it to the users’ photo gallery so that they can keep it and do whatever they want with it.

I could maybe export a json file with the data but it would be less easy for users.

Not knowing anything about what kind of app you are working on or what sort of information might be on the table, I can’t really provide any valuable ideas.

Is starting the app and seeing everything that way too cumbersome or slow? Is there any reason why the user might not be able to access the table using the app at some point? If there is some online authentication, you could add an option to save offline views of some tables on the device. An app takes a few seconds to load, whereas it can easily take me upwards of 10 seconds to get to my photos and opening the correct one.

Have you carefully considered if it is even necessary to take the data outside of the app as an image or is this a “it’d be cool if” kind of idea? I get ideas like that very often, but in a situation like this, that idea might not be worth implementing  :wink:

In fact, I’m working on an app to help students organise themselves in their revisions. The app is now finished, tested… and everything seems to work fine.

However someone told me it was quite tricky to create this kind of app as, in case of problem with the app, I would be partly responsible for a potential exam failure… Therefore, I thought I could maybe save the data outside the app itself so that users can access it whatever happens to the app. Here is how this idea came to me.

If you are worried about potential trouble resulting from possible exam failures, I’d include a clause in the app’s terms of service where you explicitly state that the app is only meant to aid in the revision process and that you, i.e. the app developer and service provider, will not be responsible for any failed exams, etc.

There are many ways you can export your data to other formats, taking a picture is the worst of them. the user will need to pinch zoom, etc to see all data if table is larger than screen, it will be a pain to use.

why not just have an export button, ou email button, you can create a simple html table and send it by email. that way the user will always have his table in their email account, they can flag it and will be pretty easy to access it. The bonus with this approach is that the user can use the data to anything he wants, like using with other programs like excel.

saying this, @Xedur gave the best answer i can think of. I was going to tell you the same thing (with worst english).