[Gambas-user] Memory admistration
Fabien Bodard
gambas.fr at ...626...
Wed Oct 31 08:25:45 CET 2007
Just to talk a little bit :
i've used the Benoit function under the script joined here,
in a concole :
Launch ./ram.g
then i ve made this simple script:
USE gb.qt
dim hForm as new form
hForm.show
and launch it via 'gbs2 test.g &'
call a new time ./ram.g
result : 2MB
nota: i use kde so qt is loaded...
nota after unload the test appli the memory decrease to be a the same level or
near.
Le Tuesday 30 October 2007 20:10:10 Benoit Minisini, vous avez écrit :
> 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,
-------------- next part --------------
#!/usr/bin/env gbs2
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
Print subst("Used memory: &1 Bytes",GetUsedMemory())
More information about the User
mailing list