Hello,
 
I'm working with DirectFB-1.0.1 on ARM cpu.
I found a memory problem.
It seems that the allocated memory not freed 
even though call window/surface->Release.
 
In my test, memory usage increase about 40Kbytes in calling a pare of 
create_window() and destroy_window().
 
My test code is as follows:
===================================================================
#include <stdio.h>
#include <stdlib.h>
#include <directfb.h>
void *window_list[1024];
void *evtbuf_list[1024];
int   window_num = 0;
IDirectFBWindow* create_window(IDirectFBDisplayLayer *layer, int x, int y, int 
w, int h)
{
 IDirectFBWindow   *window;
 IDirectFBSurface  *window_surface;
 IDirectFBEventBuffer *buffer;
 DFBWindowDescription desc;
 desc.flags  = ( DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT | 
DWDESC_CAPS );
 desc.posx   = x;
 desc.posy   = y;
 desc.width  = w;
 desc.height = h;
 desc.caps   = DWCAPS_ALPHACHANNEL;
 layer->CreateWindow( layer, &desc, &window );
 window->GetSurface( window, &window_surface );
 window_surface->SetColor( window_surface, 0xFF, 0x20, 0x20, 0xFF );
 window_surface->DrawRectangle( window_surface, 0, 0, desc.width, desc.height );
 window_surface->Flip( window_surface, NULL, 0 );
 window->SetOpacity( window, 0xFF );
// window->AttachEventBuffer( window, buffer );
 window_surface->Release( window_surface );   // not freed?
 return window;
}
void destroy_window(IDirectFBWindow *window)
{
 window->Release( window );      // not freed?
}
int main( int argc, char *argv[] )
{
 IDirectFB              *dfb;
 IDirectFBDisplayLayer  *layer;
 IDirectFBWindow        *window;
 IDirectFBWindow        *window_tmp;
 IDirectFBSurface       *window_surface;
 IDirectFBEventBuffer   *buffer;
 DFBWindowEvent     evt;
 DFBDisplayLayerConfig   layer_config;
 DFBGraphicsDeviceDescription gdesc;
 DFBWindowID      id;
 int quit = 0;
 DirectFBInit( &argc, &argv );
 DirectFBCreate( &dfb );
 printf("\n\n");
 printf("--------------------------------------------\n");
 printf("   a key : Create new window\n");
 printf("   b key : Delete the last window\n\n");
 printf("   c  key : Quit\n");
 printf("--------------------------------------------\n\n");
 dfb->GetDeviceDescription( dfb, &gdesc );
 dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer );
 layer->SetCooperativeLevel( layer, DLSCL_ADMINISTRATIVE );
 if (!((gdesc.blitting_flags & DSBLIT_BLEND_ALPHACHANNEL) &&
  (gdesc.blitting_flags & DSBLIT_BLEND_COLORALPHA  )))
 {
  layer_config.flags = DLCONF_BUFFERMODE;
  layer_config.buffermode = DLBM_BACKSYSTEM;
  layer->SetConfiguration( layer, &layer_config );
 }
 layer->GetConfiguration( layer, &layer_config );
 layer->EnableCursor ( layer, 1 );
 {
  DFBSurfaceDescription sdsc;
  DFBWindowDescription  desc;
  desc.flags = ( DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT );
  desc.caps = DWCAPS_ALPHACHANNEL;
  desc.flags |= DWDESC_CAPS;
  sdsc.width  = 320;
  sdsc.height = 240;
  desc.posx   = 0;
  desc.posy   = 0;
  desc.width  = sdsc.width;
  desc.height = sdsc.height;
  layer->CreateWindow( layer, &desc, &window );
  window->GetSurface( window, &window_surface );
  window->SetOpacity( window, 0xFF );
  window->CreateEventBuffer( window, &buffer );
  window_surface->SetColor( window_surface, 0x80, 0xa0, 0x00, 0x90 );
  window_surface->FillRectangle( window_surface, 0, 0, desc.width, desc.height 
);
  window_surface->Flip( window_surface, NULL, 0 );
  window->GetID( window, &id );
 }
 while (!quit) {
  buffer->WaitForEventWithTimeout( buffer, 0, 10 );
  while (buffer->GetEvent( buffer, DFB_EVENT(&evt) ) == DFB_OK) 
  {
   if (evt.window_id == id)
   {
    switch (evt.type) 
    {
    case DWET_BUTTONDOWN: break;
    case DWET_BUTTONUP:  break;
    case DWET_KEYDOWN:  break;
    case DWET_KEYUP:
//     printf("DWET_KEYUP key_id=%d key_code=%d\n", evt.key_id, evt.key_code);
     if (evt.key_id == 62977)
     {
//      printf("create new window\n");
      window_tmp = create_window(layer, 0, 0, 100, 100);
      window_tmp->RequestFocus( window_tmp );
      window_tmp->RaiseToTop( window_tmp );
      window_list[window_num] = (void*)window_tmp;
      window_num++;
     }
     else if (evt.key_id == 62979)
     {
//      printf("destroy window\n");
      if (window_num>0)
      {
       window_num--;
       destroy_window((IDirectFBWindow*)window_list[window_num]);
      }
     }
     else if (evt.key_id == 62978)
     {
      quit = 1;
      exit(0);
     }
     break;
    default:
     break;
    }
   }
  }
 }
 buffer->Release( buffer );
 window_surface->Release( window_surface );
 window->Release( window );
 layer->Release( layer );
 dfb->Release( dfb );
 return 0;
}
=================================================================================
 
Any ideas?
 
Thanks,
Jess
_______________________________________________
directfb-users mailing list
directfb-users@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users

Reply via email to