Page 1 of 4

HMG_Upper() function causes a memory leak

Posted: Mon Sep 19, 2016 1:11 pm
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

Re: HMG_Upper() function causes a memory leak

Posted: Mon Sep 19, 2016 1:15 pm
by srvet_claudio
I will check.

Re: HMG_Upper() function causes a memory leak

Posted: Mon Sep 19, 2016 5:09 pm
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

Re: HMG_Upper() function causes a memory leak

Posted: Mon Sep 19, 2016 5:33 pm
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

Re: HMG_Upper() function causes a memory leak

Posted: Mon Sep 19, 2016 5:46 pm
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.

Re: HMG_Upper() function causes a memory leak

Posted: Mon Sep 19, 2016 10:17 pm
by Roberto Lopez
There is not memory consumption increase here (Windows 7 32 bits).

Re: HMG_Upper() function causes a memory leak

Posted: Tue Sep 20, 2016 10:47 am
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

Re: HMG_Upper() function causes a memory leak

Posted: Tue Sep 20, 2016 11:11 am
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

Re: HMG_Upper() function causes a memory leak

Posted: Tue Sep 20, 2016 11:25 am
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

Re: HMG_Upper() function causes a memory leak

Posted: Tue Sep 20, 2016 1:01 pm
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.