Which objects must be released explicitly

Postby Antonio Linares » Fri Aug 01, 2008 11:52 pm

Enrico and others,

This concept is quite simple and common for all operating systems:

An application can not put in risk the stability of the operating system. Specially for those operating systems designed to run multiple applications simultaneously.

This concept is fundamental for the stability and security of an operating system. In other words: if this simple concept fails, then the entire operating system could crash due to an application activity. So the operating system protects itself against these potential problems.

On next msgs we are going to check this concept with some simple examples.
Last edited by Antonio Linares on Sat Aug 02, 2008 12:31 am, edited 1 time in total.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41461
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Sat Aug 02, 2008 12:00 am

1. Lets try to block the system:

On this example I try to block Windows, calling a recursive C function. Please run this test and see how Windows detects the problem and blocks the application:

Code: Select all  Expand view
function Main()

  CrashTheSystem()

return nil

#pragma BEGINDUMP

#include <hbapi.h>

void CrashIt( void )
{
   CrashIt();
}

HB_FUNC( CRASHTHESYSTEM )
{
   CrashIt();
}

#pragma ENDDUMP   
Last edited by Antonio Linares on Sat Aug 02, 2008 12:49 am, edited 1 time in total.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41461
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Sat Aug 02, 2008 12:17 am

2. In this example we are going to create a crazy amount of brushes without releasing them. Please open the task manager and check the physical memory used: You will notice that it remains the same after the application execution:

Code: Select all  Expand view
function Main()

   CreateLotsOfBrushes()
   
return nil

#pragma BEGINDUMP

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

HB_FUNC( CREATELOTSOFBRUSHES )
{
   LONG l;
   LOGBRUSH lb;
   
   lb.lbStyle = BS_SOLID;
   lb.lbColor = RGB( 255, 255, 255 );
   lb.lbHatch = HS_CROSS;
   
   for( l = 0; l < 10000000; l++ )
      CreateBrushIndirect( &lb );
}

#pragma ENDDUMP       
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41461
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Sat Aug 02, 2008 12:29 am

3. In this example we are going to try a direct attack to the operating system: We request a huge global memory, so Windows will not know if such memory has to be released, so the entire system can get in danger. But again, Windows properly protects itself. Please check physical memory from the task manager:

Code: Select all  Expand view
function Main()

   SystemAttack()
   
return nil

#pragma BEGINDUMP

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

HB_FUNC( SYSTEMATTACK )
{
   LONG l;
   
   for( l = 0; l < 10000000; l++ )
      GlobalAlloc( GMEM_FIXED, 10000000 );
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41461
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Enrico Maria Giordano » Sat Aug 02, 2008 9:27 am

Great! Thank you for the samples.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8408
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Enrico Maria Giordano » Sat Aug 02, 2008 9:28 am

On which Windows versions did you try the samples?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8408
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Sat Aug 02, 2008 9:56 am

Enrico,

Vista Ultimate 32 bits
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41461
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Enrico Maria Giordano » Sat Aug 02, 2008 10:10 am

I wonder if it's the same on older Windows versions... :?:

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8408
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Sat Aug 02, 2008 10:25 am

Enrico,

Probably not.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41461
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Enrico Maria Giordano » Sat Aug 02, 2008 12:01 pm

Then better properly release resources. :-)

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8408
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Sat Aug 02, 2008 2:28 pm

Enrico,

Yes, of course. Nobody is saying the opposite.

FiveWin properly releases the ones used by the windows, dialogs and controls. If the programmer creates some more, besides those, then he is responsable for releasing them.

Though FiveWin will automatically release them at the exit of the application, in the case that the programmer didn't do it properly, and Windows itself will clean the whole application workspace finally.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41461
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby MOISES » Sun Aug 03, 2008 10:17 am

Hi,

New Harbour 1.00 RC 2 creates a file, hb_out.txt, indicating which objets are not release from memory.
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

Postby Antonio Linares » Sun Aug 03, 2008 10:20 am

Moises,

We are talking about Windows GDI objects here.

Anyhow, thanks for your info. Though I guess its Harbour responsability to release all created objects from Classes, as a result of its garbage collector activity.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41461
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 136 guests