lost memory with images in xBrowse

lost memory with images in xBrowse

Postby Marcelo Via Giglio » Mon Dec 03, 2012 3:50 am

Hello,

I have a problem with memory when work with images in xBrowse, the code of xBrowe's definition is

Code: Select all  Expand view
  REDEFINE XBROWSE oBrwG ID 112 OF oDlg ;
            COLUMNS 'imagen';
             HEADER "FOTOGRAFIAS";
           COLSIZES 100;
            JUSTIFY 2;
              ALIAS "imagenes"
 


the imagenes table is ADT and the column or field imagen is a Imagen type

When I navigate between images (rows of xBrowse) the use of memory increase ( task panel ) and don't decrease until close the app

I am using fwh 11.04 BCC 5.82 and xH 1.2

some help I will appreciate

best regards

Marcelo
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: lost memory with images in xBrowse

Postby reinaldocrespo » Tue Dec 04, 2012 12:52 am

Hey Marcelo -good to see you around.

Have you tried assigning NIL to the object and then calling garbage collection?

Code: Select all  Expand view

oBrwG := Nil
hb_GCAll( .t. )
 


I surely don't like the idea of xbrowse with images consuming all available memory....


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: lost memory with images in xBrowse

Postby Marcelo Via Giglio » Tue Dec 04, 2012 3:09 am

Dear Reinaldo,

thanks very much for response, my problem with xBrowse is when I navigate between rows, if I change from an image to other (row to row) in the xBrowse, the memory go up until the system go full.

I can add some extra info, this occur when the graphic format is other than bmp, stored in a ADT table

Thanks for your help

Regards

Marcelo
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: lost memory with images in xBrowse

Postby Marcelo Via Giglio » Tue Dec 04, 2012 3:20 pm

Hello,

from here https://www.box.com/s/3851fr0ehpjlt1h4qbw3 you can download a self-contained sample (sorry is a little big).

To see what I want to show, open the windows TASK PANEL go to the memory monitoring, open the test.exe, go to the last image in the xbrowse go back, go forward many times, you will see in the task panel memory consumption.

The difference between the last image with the other is the format JPG and BMP and size the JPG is big.

I hope there are solutions to this problem

Regards

Marcelo
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: lost memory with images in xBrowse

Postby reinaldocrespo » Tue Dec 04, 2012 3:55 pm

Hi. I confirmed the problem. I wrote my own tests using a dbf/fpt/cdx table. It does the same.

Using Marcelo's example you can simply keep pressing arrow down on the last image. It goes nowhere, as it has nowhere to go, but it keeps consuming more and more memory until it finally freezes. This points to a problem with xbrowse when showing images on a cell. Is my assumption wrong?


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: lost memory with images in xBrowse

Postby nageswaragunupudi » Tue Dec 04, 2012 8:00 pm

reinaldocrespo wrote:Hi. I confirmed the problem. I wrote my own tests using a dbf/fpt/cdx table. It does the same.

Using Marcelo's example you can simply keep pressing arrow down on the last image. It goes nowhere, as it has nowhere to go, but it keeps consuming more and more memory until it finally freezes. This points to a problem with xbrowse when showing images on a cell. Is my assumption wrong?


Reinaldo.

For every cell, it it is an image ( as in the above case ), the bitmap handle is created, painted and then destroyed immediately. So this should not effect memory.

Anyway we shall do more experiments with this to find if there is some obscure problem inside the code.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: lost memory with images in xBrowse

Postby reinaldocrespo » Tue Dec 04, 2012 10:37 pm

Mr. Rao;

It is always possible that the problem is not with xbrowse itself but rather the destroy mechanism being used to destroy the image.

Did you try Marcelo's example? It is a short-self-contained sample. The table only contains 4 images. Open the task manager and monitor the amount of memory being consumed by the application. While you do that, keep pressing down arrow. The cursor will stay at the 4th and last line as it has nowhere else to go, but keep pressing the downarrow to force xbrowse to redraw the image time after time. Can you confirm that the amount of memory used increments until the app finally crashes?


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: lost memory with images in xBrowse

Postby reinaldocrespo » Thu Dec 06, 2012 1:59 pm

Hi.

Can anyone else, please, confirm this problem?

You may use the self-contained-reduced sample posted by Marcelo on this thread. If you prefer an even simpler sample using dbf/cdx, I will gladly write one.

Thank you,


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: lost memory with images in xBrowse

Postby Maurizio » Thu Dec 06, 2012 4:54 pm

I confirmed the problem
Maurizio
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm

Re: lost memory with images in xBrowse

Postby Patricio Avalos Aguirre » Thu Dec 06, 2012 10:16 pm

Hola Marcelo

podrias colocar el código como grabas en un campo IMAGEN

lo pregunto porque yo grabo tambien en campo image pero cuando lo
veo en el data arquitec no se me ven las imagenes, solo aparecen codigo extraño ÿØÿà

pero en mi programa si funcionan las imagenes

utilizo imagen jpg de 640x480

saludos
Saludos
Patricio

__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl
User avatar
Patricio Avalos Aguirre
 
Posts: 1060
Joined: Fri Oct 07, 2005 1:56 pm
Location: La Serena, Chile

Re: lost memory with images in xBrowse

Postby Marcelo Via Giglio » Fri Dec 07, 2012 2:28 am

Hola Patricio,

I use

imagenes -> ( ADSFile2Blob( cFile, "imagen", 7 ) )

where ADS_BINARY 6 /* BLOB - any data */
ADS_IMAGE 7

but we can use this other simple method

imagenes -> imagen := MEMOREAD( cFile )

By the way, some body know how can we save an image using pure SQL

Patricio, disculpa que escriba en mi pobre inglés es por respeto al foro, y en el ARC debes poder ver la imagen

saludos

Marcelo
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: lost memory with images in xBrowse

Postby reinaldocrespo » Fri Dec 07, 2012 7:45 pm

Marcelo /Patricio;

Grato ver la pregunta.

Saving an image, or anything else for that matter, is best done via pure SQL. To save images, I prefer to use a binary field instead of a memo field. Here is some actual code (a bit reduced):

Code: Select all  Expand view

   cSql := "INSERT INTO images ( jpg ) VALUES ( :bindata ) \n"
   ADSCreateSQLStatement(  "cAlias" )
   AdsPrepareSql( cSql )
   binImage := MemoRead( cFile )
   AdsSetBinary( "bindata", binImage )
   AdsExecuteSql()
 


As you see, you must first prepare the query. Prepared SQLs execute faster, especially if your are executing the same sql inside a loop, as only the parameters change. You set parameters using ACE functions: AdsSetBinary(), AdsSetString(), AdsSetLong(), AdsSetDouble(), AdsSetDate(), AdsSetLogical(). These functions are not in included (as of now) with AdsFunc.c on harbour. They should soon be included as I recently sent them to be included as a contribution to harbour.

In the meanwhile, here is the wrappers to those functions. You only need to add this code to your adsfunc.c and rebuild rddads.lib. Then you may start using AdsSet...() funcs.

Code: Select all  Expand view

//----------------------------------
//RCB 4/25/2011 10:16:24 AM

HB_FUNC( ADSSETBINARY )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();

ulRetVal = AdsSetBinary( pArea->hStatement,
    (char*) hb_parc( 1 ),
    (hb_pcount() > 2 && hb_parni( 3 ) == 1) ? ADS_BINARY : ADS_IMAGE,
    hb_parclen( 2 ), //ulTotalLength
    0,//ulOffset
    (char*) hb_parc( 2 ),
    hb_parclen( 2 ) );

hb_retl( ulRetVal == AE_SUCCESS );
}

//----------------------------------
//RCB 4/25/2011 10:16:24 AM
HB_FUNC( ADSSETSTRING )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();

ulRetVal = AdsSetString( pArea->hStatement,
    (char*) hb_parc(1),
    (char*) hb_parc(2),
    hb_parclen(2) );
   
hb_retl( ulRetVal == AE_SUCCESS );
}

//----------------------------------
//RCB 4/25/2011 10:16:24 AM
HB_FUNC( ADSSETDATE )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();
ulRetVal = AdsSetDate( pArea->hStatement,
    (char*) hb_parc(1),
    (char*) hb_parc(2),
    hb_parclen(2) );
hb_retl( ulRetVal == AE_SUCCESS );
}

//----------------------------------
//RCB 4/25/2011 10:16:24 AM
HB_FUNC( ADSSETLONG )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();
ulRetVal = AdsSetLong( pArea->hStatement,
    (char*) hb_parc(1),
    hb_parnl(2));
hb_retl( ulRetVal == AE_SUCCESS );
}

//----------------------------------
//RCB 4/25/2011 10:16:24 AM
HB_FUNC( ADSSETDOUBLE )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();
ulRetVal = AdsSetDouble( pArea->hStatement,
    (char*) hb_parc(1),
    hb_parnd(2));
hb_retl( ulRetVal == AE_SUCCESS );
}

//----------------------------------
//RCB 4/25/2011 10:16:24 AM
HB_FUNC( ADSSETLOGICAL )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();
ulRetVal = AdsSetLogical( pArea->hStatement,(char*) hb_parc(1), hb_parl(2));
hb_retl( ulRetVal == AE_SUCCESS );
}

//RCB
HB_FUNC( ADSSETNULL )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();
ulRetVal = AdsSetNull( (hb_parnl(1)==0) ? pArea->hOrdCurrent : hb_parnl(1),(char*) hb_parc(2));
hb_retl( ulRetVal == AE_SUCCESS );
}
 


And just as a reminder to FWH community and to keep this thread focused; xBrowse is grossly eating up resources like a pig anytime you show images on it. It is easy to reproduce the problem using Marcelos's posted sample on this same thread. Is there an outlook on this problem? Anyone working on it?

Please help;


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: lost memory with images in xBrowse

Postby reinaldocrespo » Tue Dec 11, 2012 12:05 am

Any fixes available yet?

Anyone working on solving this problem?


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: lost memory with images in xBrowse

Postby Marcelo Via Giglio » Tue Dec 11, 2012 12:30 am

Reinaldo,

first thanks for sharing your code about SQL and data types.

I don't know if some body have or need to work with images in xBrowse, I hope Mr. Rao will have some time to solve this issue

un abrazo

Marcelo
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: lost memory with images in xBrowse

Postby Marcelo Via Giglio » Mon Dec 17, 2012 1:21 am

Hello,

sorry, to be present only

I hope Fivetech take imporntance about this bug

regards

Marcelo
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 75 guests