HMG_Upper() function causes a memory leak

Moderator: Rathinagiri

KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

HMG_Upper() function causes a memory leak

Post by KDJ »

I have tested the following code in real Win-XP (32 bit) and Win-7 (64 bit).
Each time you press "Test" button, consumption of memory is increased by approx 600 KB.

Code: Select all

// Press 'Test: HMG_Upper()' and observe memory usage at status bar

#include 'hmg.ch'


FUNCTION Main()

  SET FONT TO 'MS Shell Dlg', 8

  DEFINE WINDOW MUT_WA;
    COL    200;
    ROW    100;
    WIDTH  340;
    HEIGHT 120;
    TITLE  'Memory usage test';
    MAIN

    DEFINE BUTTON Test_BU
      COL      10
      ROW      20
      WIDTH   150
      HEIGHT   25
      CAPTION 'Test: HMG_Upper()'
      ACTION  DoTest()
    END BUTTON

    DEFINE BUTTON Exit_BU
      COL     170
      ROW      20
      WIDTH   150
      HEIGHT   25
      CAPTION 'Exit'
      ACTION  MUT_WA.RELEASE
    END BUTTON

    DEFINE STATUSBAR
      STATUSITEM ''
    END STATUSBAR

    DEFINE TIMER MUT_WA_TI;
      INTERVAL 1000;
      ACTION   UpdateStatus()

    ON KEY ESCAPE ACTION MUT_WA.RELEASE

  END WINDOW //MUT_WA

  UpdateStatus()
  MUT_WA.ACTIVATE

RETURN NIL


FUNCTION DoTest()
  LOCAL n
  LOCAL cString := 'abcdefgh'

  FOR n := 1 TO 10000
    HMG_Upper(cString)

    //HMG_Lower(cString)
    //Upper(cString)
    //Lower(cString)
    //HMG_CallDLL('User32.dll', 0, 'CharUpper', cString)
  NEXT

  UpdateStatus()

RETURN NIL


FUNCTION UpdateStatus()

  MUT_WA.STATUSBAR.Item(1) := 'Memory usage: ' + LTrim(Str(GetProcessMemoryInfo()[3] / 1024, 10, 0) + ' KB')

  //RELEASE MEMORY does not work in Win-XP, in Win-7 works
  //RELEASE MEMORY

RETURN NIL
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: HMG_Upper() function causes a memory leak

Post by srvet_claudio »

I will check.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: HMG_Upper() function causes a memory leak

Post by serge_girard »

Claudio,

Is it good practice to put a 'RELEASE MEMORY' on several places in a program OR should it be done "automatically" ?

Serge
There's nothing you can do that can't be done...
EduardoLuis
Posts: 682
Joined: Tue Jun 04, 2013 6:33 pm
Location: Argentina

Re: HMG_Upper() function causes a memory leak

Post by EduardoLuis »

Hi friends:

I've test your sample under different versions of HMG since 3.030 to 3.43 and the result is the same: up 600kb each time is pressed the button.-
So previously Claudio you change anything on new version, i suppose there is no issue with HMG_Upper() and 3.43.-
Just for the records, the test was made on a PC with win XP SP3 and only 512mg ram.-
As never hangs up the program or the OS, i made the test till memory on status shows 390.000kb.-
Just a test.-
With regards.
Eduardo

Hola Amigos:

He testeado el ejemplo bajo diferentes versions de HMG desde la version 3.030 hasta la 3.43 y el resultado fue el mismo: 600kb hacia arriba cada vez que se presionba el botón.-
Por eso, Claudio, previamente antes que introduzcas algun cambio en la proxima version, supongo que esto no es un defecto de HMG_Upper() en la 3.43.-
Para el registro, este test fue hecho en una PC con Win XP SP3 y solo 512mg. ram.-
Como el programa nunca se colgó y tampoco el SO, por lo tedioso del test lo realizé hasta que la barra de status mostró 390.000kb.-
Es solo un test.-
Cordialmente
Eduardo
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: HMG_Upper() function causes a memory leak

Post by KDJ »

serge_girard wrote:
Is it good practice to put a 'RELEASE MEMORY' on several places in a program OR should it be done "automatically" ?
1. This test program almost does nothing, only converts string to uppercase. So why to use "RELEASE MEMORY"?
2. Using Upper(cString) function or HMG_CallDLL('User32.dll', 0, 'CharUpper', cString) instead of HMG_Upper(cString) does not result in increased memory usage.
3. "RELEASE MEMORY" does not work in Windows XP.
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: HMG_Upper() function causes a memory leak

Post by Roberto Lopez »

There is not memory consumption increase here (Windows 7 32 bits).
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: HMG_Upper() function causes a memory leak

Post by mustafa »

Try ? have if it works

*------------------------------------------------------------------------------------------------------------------------------------*
DEFINE WINDOW MUT_WA;
COL 200;
ROW 100;
WIDTH 340;
HEIGHT 120;
TITLE 'Memory usage test';
MAIN

View Post luisvasquez --> viewtopic.php?f=43&t=4738&start=70

----------- here this code -------------> DEFINE TIMER Timer_1 INTERVAL 1000 ACTION (RELEASE MEMORY)

DEFINE BUTTON Test_BU
COL 10
ROW 20

*-----------------------------------------------------------------------------------------------------------------------------------*

Saludos/Regarts
Mustafa
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: HMG_Upper() function causes a memory leak

Post by serge_girard »

Hello,

What I meant is :

Is it necessary to put a 'RELEASE MEMORY' on (via TIMER) in a program ?
OR
should it be done automatically in HMG-sources
OR
Is it a temporarily problem?

I think only Claudio or Rathi knows the right answer?

Regards, Serge
There's nothing you can do that can't be done...
User avatar
dragancesu
Posts: 920
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: HMG_Upper() function causes a memory leak

Post by dragancesu »

This program is classic for compiler test, code like

FOR I = 1 TO 10000
x = 1
NEXT

is one step, this code can be compiled like X = 1, in this case compiler must be clever then programer and correct programer's bad code

x = 0
FOR I = 1 TO 10000
x = x + 1
NEXT

can be loop 10000 times
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: HMG_Upper() function causes a memory leak

Post by Rathinagiri »

serge_girard wrote:Hello,

What I meant is :

Is it necessary to put a 'RELEASE MEMORY' on (via TIMER) in a program ?
OR
should it be done automatically in HMG-sources
OR
Is it a temporarily problem?

I think only Claudio or Rathi knows the right answer?

Regards, Serge
IMHO, the memory resources once not needed shall be released automatically.

For some memory hungry programs (with huge image manipulation), I think we shall use release memory.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply