[Gambas-user] Memory admistration

David Villalobos Cambronero david_villalobos_c at ...43...
Wed Oct 31 13:12:15 CET 2007


Many thanks, thats what I wanted, I wanted to understand ¡why!

regards

David

----- Original Message ----
From: Benoit Minisini <gambas at ...1...>
To: mailing list for gambas users <gambas-user at lists.sourceforge.net>
Sent: Tuesday, October 30, 2007 7:10:10 PM
Subject: Re: [Gambas-user] Memory admistration


On mardi 30 octobre 2007, Daniel Campos wrote:
> What kind of memory? Any modern O.S. uses to let programs more memory
> than needed when there's not need to provide memory to other
 programs,
> that is, you can find that a program is apparently using 200Mb even
 if
> it is using only 100Mb, the O.S. simply reserves that memory for
> possible future use of the program (if the user loads the form again,
> for example) so memory allocations become faster.
>
> 2007/10/30, David Villalobos Cambronero
 <david_villalobos_c at ...43...>:
> > Hi all,
> >
> >     I want to know if someone can give a small explanetion about
 how
> > Gambas administrates the RAM.
> >
> >     I made a small aplication that has a label that shows the
 amount of
> > memory used by the itself. When program starts the label shows
 arround
> > 20MB. It seems normal.
> >
> >     Then if I open report (Form with a webbrouser that show the
> > information of a query), the memory increases to 26MB. It seems
 normal.
> >
> >     But when I close the Form the memory used continue been 26MB or
 25MB.
> >
> >     I just want to know how Gambas deals with memory to try to find
 the
> > problem.
> >
> > Best regards.
> >
> > David
> >
> >

To solve this problem, i.e. to know how much RAM is really used by the 
program, I suggest using the following function:

PRIVATE FUNCTION GetUsedMemory() AS Integer

  DIM sRes AS String
  DIM aRes AS String[]
  DIM cVal AS NEW Collection
  DIM sVal AS String

  EXEC ["cat", "/proc/meminfo"] TO sRes
  FOR EACH sVal IN Split(sRes, "\n", "", TRUE)
    aRes = Split(sVal, " ", "", TRUE)
    cVal[Left$(aRes[0], -1)] = CInt(aRes[1])
  NEXT

  RETURN cVal!MemTotal - cVal!MemFree - cVal!Buffers - cVal!Cached + 
cVal!SwapTotal - cVal!SwapFree - cVal!SwapCached

END

Call this function to get the memory used by the system (without swap
 and 
cache), run something (a full application, a function...), then call
 this 
function again. The difference is the RAM really used by your
 application or 
function.

Note that opening the IDE project in the gambas IDE uses about 5 Mb of
 RAM. 
But this is on KDE where the QT library is already loaded.

And note that at the moment the gambas interpreter never unload a
 class. So 
opening a form and closing it only frees the dynamic data used by the
 form, 
but not the memory used by the class (class information, bytecode,
 debugging 
symbols...)

Regards,

-- 
Benoit Minisini

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Gambas-user mailing list
Gambas-user at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user





__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the User mailing list