CallDll32() memory leak

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

kristalist
Posts: 21
Joined: Thu Apr 23, 2015 2:30 pm
DBs Used: DBF

CallDll32() memory leak

Post by kristalist »

Hi all!
In my program I need to call external library every 0.1-0.3 sec. In case I used CallDll32 I can see constantly increasing of used memory.
I tested CallDll32 with common standard function with the same effect.
For example in this test after 20-40 min we can see used memory increased ( My system Win7Pro64, HMG 3.3.1). Can anyone understand my problem and help me?

Code: Select all

 
REQUEST HB_GT_WVT_DEFAULT
#include "hmg.ch"
Function Main
static nFlags  
    REQUEST HB_LANG_LT
    REQUEST HB_CODEPAGE_LTWIN
    hb_setTermCP("UTF8EX","cp1257",.F.)
    hb_cdpSelect( "cp1257" )
    SetMode(25,80)
    cls 
  
  
   nFlags :=space(10)
  
   do while .T.
         tnk:=nextkey()
            if tnk=27 /// exit on esc pressed
                  exit
            endif
            if tnk>0
                inkey()
            endif 
            CallDll32( "InternetGetConnectedState", "WININET.DLL", @nFlags, 0 )
   end
Return
 
Thanks in advance.

Best regards,
Konstantins Orlovskis (kristalist)
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

CallDll32() memory leak

Post by Pablo César »

Hi Konstantins have you welcome to our community !

Your are using in console mode and keyboard buffering. This is Harbour (better said) xbase (language) problem or behaviour.

All regarding keyboard is buffering and what I know is in Clipper for example, was a problem of garbage collector of memory usage. At Harbour I believe some particulars is still keeping.

I saw youre using Inkey(), why do not use Inkey(0.1) ? Probably you will alleviate the problem.

In GUI I would suggest to use Timer instead Inkey and NextKey.

Do not forget you are in looping trying all the time reading your buffering... this would demmands a lot of memory after a long time running.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
kristalist
Posts: 21
Joined: Thu Apr 23, 2015 2:30 pm
DBs Used: DBF

Re: CallDll32() memory leak

Post by kristalist »

Hello Pablo!

Many thanks for attention!
Pablo César wrote:All regarding keyboard is buffering and what I know is in Clipper for example, was a problem of garbage collector of memory usage.
- at this moment I have a same numbers my program installed at GAS station. FreeDOS, Blinker, Clipper program compiling with many p-code DLL and linked in protected mode. Work with continuously scanning com ports and periodically Nowell IP 32 stack 24h/7d/week without any problem with memory :-) But I got tired update my old POS-ECR DOS programm for new technology...
Pablo César wrote:At Harbour I believe some particulars is still keeping.
- for better compatibility ? :-)
Pablo César wrote:I saw youre using Inkey(), why do not use Inkey(0.1) ? Probably you will alleviate the problem.
- I tried inkey(0.1). The problem is kept.
- I deleted inkey() -, The problem is kept.
Pablo César wrote:In GUI I would suggest to use Timer instead Inkey and NextKey.
-I tested simple form with one object- timer with interval=1 and action: (see code) - and problem is kept! Memory usage increasing, periodicaly decreased but decreasing is little and cannot compensate decreasing. For 30 min : memory using increased from ~2700K to ~ 7400K by task manager! I think it is not normal....

Code: Select all

#include "hmg.ch"
static nFlags
declare window Main

Function main_timer_1_action
nFlags :=space(10)
 CallDll32( "InternetGetConnectedState", "WININET.DLL", @nFlags, 0 )
Return Nil
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

CallDll32() memory leak

Post by Pablo César »

I did not prepared HMG GUI sample to test it, probably tomorrow I will do.

We are having troubles regarding CallDll32 function (Please read this topic) probably you should try other solutions like this for replacing your procedure routine:

http://www.codeproject.com/Tips/147662/ ... nnectivity
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
kristalist
Posts: 21
Joined: Thu Apr 23, 2015 2:30 pm
DBs Used: DBF

Re: CallDll32() memory leak

Post by kristalist »

I did not prepared HMG GUI sample to test it, probably tomorrow I will do.
see atachment :-)
probably you should try other solutions like this for replacing your procedure routine:

http://www.codeproject.com/Tips/147662/ ... nnectivity
:-( I cannot :-(

With this function it's only example. In real application I need to call (several times on every seconds) special function in external DLL to control fuel despenser.... 22 hours- 7days week.
Attachments
t3dll.zip
(1.25 MiB) Downloaded 199 times
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

CallDll32() memory leak

Post by Pablo César »

Hi Konstantin,

I made this sample based from your sample:

Code: Select all

#include <hmg.ch>

Function Main
Static nFlags

DEFINE WINDOW Form_1 AT 256 , 357 WIDTH 550 HEIGHT 350 TITLE "" MAIN

    ON KEY ESCAPE ACTION ThisWindow.Release
	
    DEFINE TIMER Timer_1 INTERVAL 1000 ACTION Main_Timer_1_Action()
	
	DEFINE STATUSBAR FONT "Courier New" SIZE 9
        STATUSITEM " <Esc> to exit"
    END STATUSBAR

END WINDOW
Form_1.Center
Form_1.Activate
Return Nil

Function Main_Timer_1_Action()
Local nFromHnd:=GetFormhandle("Form_1")
Local nId:=GetControlId("Timer_1","Form_1")
nFlags :=space(10)
If CallDll32( "InternetGetConnectedState", "WININET.DLL", @nFlags, 0 ) = 0
   KillTimer( nFromHnd, nId )
   MsgStop(" Without Internet !", "Warning" ) // Send BrodCast Message thru LAN
   InitTimer ( nFromHnd, nId, 1000 )
Endif
Return Nil
I saw you used a very short interval for timer. This it it would gives a breather...

I hope you enjoy and be helpful ! :D
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
kristalist
Posts: 21
Joined: Thu Apr 23, 2015 2:30 pm
DBs Used: DBF

Re: CallDll32() memory leak

Post by kristalist »

Hi Pablo!

From my cross-discussion from google groups https://groups.google.com/forum/#!topic ... oLQFjrMh4E
with this test from M.Ronaldo with my changes I can see memory leak (?) without CallDll32 but only with LoadLibrary() in function GETPROCESSMEMORYINFO(), and, probably , with any function that contain calling external DLL internaly (?).

my latest test in attachments with results:

Code: Select all

11:00:18
nFlags                            Memory      WorkingSetSize
----------------------------------------
??                                         4194303             7729152
??                                         4194303             7741440
??                                         4194303             7741440
.........
??                                         4194303            80478208
??                                         4194303            80478208
??                                         4194303            80478208
??                                         4194303            80482304
??                                         4194303            80482304
??                                         4194303            80482304
??                                         4194303            80482304
??                                         4194303            80482304
??                                         4194303            80482304
??                                         4194303            80482304
??                                         4194303            80482304
11:00:32

Attachments
t5dll_2.zip
(1.1 MiB) Downloaded 204 times
PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: CallDll32() memory leak

Post by PeteWG »

Hi,

In my humble opinion , the "calldll32(...)" function as it is implemented in both HMG & HMG extended sources (h_controlmisc.prg) is broken!

I would suggest to remove it and let applications use the (same name) function of harbour by linking hbmisc contrib library.

regards,

---
Pete
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

CallDll32() memory leak

Post by Pablo César »

Hi Konstantin,

Let me know a bit some more of what you expect to do with your first posted routine ?

Code: Select all

nFlags :=space(10)

do while .T.
   tnk:=nextkey()
   if tnk=27      // exit on esc pressed
      exit
   endif
   if tnk>0
      inkey()
   endif 
   CallDll32( "InternetGetConnectedState", "WININET.DLL", @nFlags, 0 )
enddo
In this code you execute InternetGetConnectedState function but what are you doing with the result of it ?

Another question is why do not use the Bernard Mouille solution ?
This is what at my previous message I've indicated to you: to change for other solution instead CallDll32.

My next suggestion is to test with IsWebConnect() replacing CallDll32( "InternetGetConnectedState", "WININET.DLL", @nFlags, 0 ) and then let us know your average time. IMHO, depending how is your interval time, ie if you have give a little slow time in the loop. Do you agree in my previous example the interval for timer do not need to be equal 1 (I do not think is so necessary for this extreme testing, does it necessary ?).

Please reevaluate following test or adapt to your code:

Code: Select all

#include <hmg.ch>

Function Main()
DEFINE WINDOW Form_1 AT 256 , 357 WIDTH 550 HEIGHT 350 TITLE "Testing Internet Connection" MAIN

    ON KEY ESCAPE ACTION ThisWindow.Release
	
    DEFINE TIMER Timer_1 INTERVAL 1000 ACTION Main_Timer_1_Action()
	
	DEFINE STATUSBAR FONT "Courier New" SIZE 9
        STATUSITEM " <Esc> to exit"
    END STATUSBAR

END WINDOW
Form_1.Center
Form_1.Activate
Return Nil

Function Main_Timer_1_Action()
Local nFromHnd:=GetFormhandle("Form_1")
Local nId:=GetControlId("Timer_1","Form_1")

If IsWebConnect() == 0
   /* Follwing commands, do not need to be like that. 
   This is just to exemplify what can it be done in case not connection found. */
   
   KillTimer( nFromHnd, nId )
   MsgStop(" Without Internet !", "Warning" ) // Send BrodCast Message thru LAN
   InitTimer ( nFromHnd, nId, 1000 )
   
Endif
Return Nil

#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>
#include <wininet.h>

HB_FUNC( ISWEBCONNECT )
{

 int nRetour = 0;
 DWORD state;

 if ( InternetGetConnectedState( &state, 0 ) != FALSE )
 {
  nRetour = 1;
 }

 hb_retni( nRetour );

}
#pragma ENDDUMP
And please let us know results.

PeteWG wrote:Hi,

In my humble opinion , the "calldll32(...)" function as it is implemented in both HMG & HMG extended sources (h_controlmisc.prg) is broken!

I would suggest to remove it and let applications use the (same name) function of harbour by linking hbmisc contrib library.

regards,

---
Pete
Hi Pete, thank you for your opinion and indication regarding CallDll32 HMG function.

I have tested the Harbour's function but with no success. But probably in my tests I have done something wrong.

I will make some tests cutting off CallDll32 function from HMG and will revert in this topic. And I will appreciated to treat this matter in this topic just to avoid off topic here.

My kind regards to all
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
kristalist
Posts: 21
Joined: Thu Apr 23, 2015 2:30 pm
DBs Used: DBF

Re: CallDll32() memory leak

Post by kristalist »

Hi Pablo!
In this code you execute InternetGetConnectedState function but what are you doing with the result of it ?
Another question is why do not use the Bernard Mouille solution ?
This is what at my previous message I've indicated to you: to change for other solution instead CallDll32.
probably you should try other solutions like this for replacing your procedure routine:
http://www.codeproject.com/Tips/147662/ ... nnectivity
As I wrote in previous post :
:-( I cannot :-(

With this function it's only example. In real application I need to call (several times on every seconds) special function in external DLL to control fuel despenser.... 22 hours- 7days week.
My goal is not to test internet connection --- but have possibility dynamical load and call any external function in std dll libraries..... :-(
Post Reply