It is currently Wed Jun 28, 2017 12:20 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Intentional OOM Error?
Unread postPosted: Mon Mar 09, 2015 6:10 pm 
Offline
User avatar

Joined: Sat Aug 24, 2013 1:37 pm
Posts: 85
Say, has anyone ever tried this?

This little program intentionally generates an OOM Error!

Yes! An Out Of Memory Error!

It creates 1meg BMP Images until it crashes!

My small tablet does 67! The big one does 59!

Does that mean an app can access upto 67 meg on my small tablet?

And can an OOM error be captured by an on error: command?

Code:
!display test
! -----------------------
!Create bitmaps for screen,
! same size as hardware screen.
!make as many as possible until
! out of memory. Highest number on
! output console is number

!Dim Array
Dim A[500]

gr.open 255,0,0,0,1,1
GR.SCREEN MGX,MGY
GR.TEXT.SIZE 17
GR.TEXT.TYPEFACE 2
GR.TEXT.HEIGHT sz,up,dn
totsz=dn-up
GR.TEXT.WIDTH tw,"Q"

p=mgx * mgy * 4
print "size of screens. of screen: ";p;" bytes."

For x = 1 to 400
GR.BITMAP.CREATE A[x],500,500
print x
next

GR.CLOSE
END

OnError:
t=x * p
print "total bytes:";t
end

_________________
I love RFO basic!

Tablets owned:
Hisense Sero 7 Pro
Samsung Galaxy Player 5.0


Top
 Profile  
 
 Post subject: Re: Intentional OOM Error?
Unread postPosted: Wed Mar 11, 2015 12:22 am 
Offline

Joined: Sat Dec 22, 2012 2:32 pm
Posts: 834
post17908.html#p17908


Top
 Profile  
 
 Post subject: Re: Intentional OOM Error?
Unread postPosted: Wed Mar 11, 2015 6:01 am 
Offline

Joined: Sat Feb 21, 2015 6:15 am
Posts: 7
Location: Lille
I've just tested your app on my (netbook) Asus 1101HA. The count goes up to 194 bitmaps before the memory error.

How do you check the quantity of memory you have onboard? This netbook is supposed to have 1024Mb of memory but I've seen somewhere that only 220Mb are used.

(edited to correct some mispellings)


Last edited by Fred59110 on Wed Mar 11, 2015 12:15 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Intentional OOM Error?
Unread postPosted: Wed Mar 11, 2015 7:04 am 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2802
Location: Colorado, U.S.
You get the amount of memory onboard from the specifications of your device. But that's not the number you want. Android caps the amount of memory available to each app when it is running. The cap is static, set by the manufacturer of the device. Android provides a number called the "memory class" that gives you the approximate value of the per-app memory limit. When Android started, the cap was around 16 meg, but it keeps getting bigger.

The undocumented command, DEBUG.STATS, dumps data to the console. The very first line is the "Mem class". (That line is new in v01.85.) My Moto G says 96, meaning each app is limited to about 96 meg. I don't know if that is MB or MiB.

- Marc


Top
 Profile  
 
 Post subject: Re: Intentional OOM Error?
Unread postPosted: Wed Mar 11, 2015 11:38 am 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2802
Location: Colorado, U.S.
I'm sorry, I forgot to answer the other half of the question.
SirDonzer wrote:
And can an OOM error be captured by an on error: command?
The general answer is "no". If you run out of memory, and you don't know where it happened, there is no reliable way to recover. The OOM left something in a bad state, and it's hard to know exactly what. The OOM is detected as BASIC! is on the way down, and there is no safe way to stop it.

In some special cases, we do know where it happened. For one rather important example, if GR.Bitmap.Create can't create the bitmap because there is not enough memory, BASIC! can catch that condition and report it. There is no damage done, so you can trap the error and recover.

Unfortunately, I just ran a test and the OOM did not get caught. I see why, and I think I can fix it for future versions of BASIC!. Until then the general "no" is a universal "no".

- Marc


Top
 Profile  
 
 Post subject: Re: Intentional OOM Error?
Unread postPosted: Wed Mar 11, 2015 12:14 pm 
Offline

Joined: Sat Feb 21, 2015 6:15 am
Posts: 7
Location: Lille
>Mougino
Thanks for your answer, alas debug.stats don't output anything.

A quick search in the parameters gives 588 Mbytes of memory for apps and multimedia.

This little app says the screen size is of 2998272 bytes, 196 bitmaps were allocated in this run, so the occupied memory is of 573.888 Mbytes. This is consistent with the 588Mbytes returned by the system


Top
 Profile  
 
 Post subject: Re: Intentional OOM Error?
Unread postPosted: Wed Mar 11, 2015 2:43 pm 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2802
Location: Colorado, U.S.
Sorry, Fred. I didn't mention that it's like the other Debug commands: you must first turn debug on.
Code:
DEBUG.ON
DEBUG.STATS


Top
 Profile  
 
 Post subject: Re: Intentional OOM Error?
Unread postPosted: Thu Mar 12, 2015 12:59 am 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2802
Location: Colorado, U.S.
jMarc wrote:
I think I can fix it for future versions of BASIC!.
BASIC! now explicitly detects and reports Out of Memory for:
GR.BITMAP.CREATE
GR.BITMAP.CROP
GR.BITMAP.LOAD
GR.BITMAP.SCALE
GR.SCREEN.TO_BITMAP
TONE

You can trap the error by looking for "java.lang.OutOfMemoryError". Sorry about the raw Java message, but for the time being I prefer to keep it. The only exception is for GR.BITMAP.LOAD. There are several ways a LOAD can fail. If any of them happens, you get Paul's original message, "Bitmap load failed at:" followed by the line with the error.

Most other places that display raw Java error messages will display a shorter message than they used to.

I fixed a lurking null pointer crash in error message reporting (ironic, no?), but chances are good it has never happened to you.

These changes will be in the next release, v01.86. If you can't wait, there will be a bugfix test build v01.85.07 in the next day or two.

- Marc

EDIT: Added GR.SCREEN.TO_BITMAP to the list (March 13)


Top
 Profile  
 
 Post subject: Re: Intentional OOM Error?
Unread postPosted: Thu Mar 12, 2015 4:15 am 
Offline

Joined: Sat Feb 21, 2015 6:15 am
Posts: 7
Location: Lille
Thanks Mougino, mem class reports 192. Now I don't understand how 196 bitmaps weighting 2998272 bytes could hold in this amount of memory.

2998272 / 1024 / 1024 * 196 = 560.4375 megabytes

Am I wrong in the above calculation or is there memory allocation while an app is running?

My screen size is 1024x732

This weird height of 732 pixels is due to a bad video driver in androidx86, the real screen size should be 1366x788


Top
 Profile  
 
 Post subject: Re: Intentional OOM Error?
Unread postPosted: Thu Mar 12, 2015 4:55 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5543
Location: Paris, France
Why do you call jMarc mougino?

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
suspicion-preferred