   Destroy_BOB doesn't work help me please !!
  Hello all , I am making a game in DirectX still using DDRAW , but anywayi`m using the BOB(Blitter Objects) used by Andre Lamoth in his book Tricks of the windows game programming gurus , but I have problem , I dont understand why Destroy_BOB doesn't actually free up memory !? I tried to search on internet ,and i saw that every single demo only uses Destroy_BOB at the game shutdown..but then...what's the point in that ? the memory will be realeased anyway...i WANT to do it dynamically..because I cannot load my entire game into memory it's too big.OK in my game I have this test in the main loop so it runs this piece of code a lot...Create_BOB(&test, 1,1,100,100,1,BOB_ATTR_MULTI_ANIM ,0,_RGB16BIT565(0,0,255),16);Load_Bitmap_File( &bitmap16bit, "test.bmp" ); Load_Frame_BOB16(&test,&bitmap16bit,0,0,0,BITMAP_EXTRACT_MODE_ABS );Unload_Bitmap_File(&bitmap16bit);Destroy_BOB(&test);WHY is it eating up all my memory !!? I mean i create it and destroy it...it's suppose to give the memory back..if somebody knows what to do..PLEASE tell me please...Thank you   
  I don't know much about the "BOB" structure.However, generally I only free my resources at the end of the program. I don't think it is good to load and free your resources right when you use them.I also doubt that your program is so big that you can't load it all into memory. However, I don't know all the circumstances, but that is just my opinion.   ;  How do you measure memory usage?;  Oh man, you are using the Windows Game Programming for Dummies book, aren't you? Burn it, it will keep you warm this winter. The genral feeling is that Andre Lamothe has no clue what he is talking about, and using the BOB structure is just a throwback to the Amiga heydays.I would start off with SDL, it's so much easier to get started with.   ;  Well i`m too far in to turn back now and use something else.And no i`m not destroying something i just created thats just a quick test to see if it does indeed realease the memory and it DOESN'T !I cannot load my whole game , because it's a game where the background changes A LOT and putting like 600+ 800X600 bitmaps into memory is not an option so I HAVE to release that memory each time.Or at least tell me how to make sure all the memory is released otherwise..can free(whaterver); fail ?Uuurhg..please anyone !   ;  I'm not entirely sure why I still have this book, but I'll see what I can do for you.BOB test;Create_BOB(&test, 0,0, 100,100, 1, BOB_ATTR_SINGLE_FRAME, 0);Destroy_BOB(&test);Does that much work for you? You may not be loading some of the files correctly, or something.I must stress again, this is about the worst and most complicated graphics library available. It is stuck half way inbetween using handles and pointers, and is excessively complicated.In nearly every other API, you allocate memory like this...API_Surface *temp;temp = API_LoadSurfaceFromFile("path/to/file.jpg");...API_DestroySurface(temp);or like thisint iHandle;iHandle = API_LoadSurfaceFromFile("path...");...API_DestroySurface(iHandle);you can't call free on the surface you are creating, with BOB because it is static memory allocated when the program is first executed, on the stack. You can only free or delete things allocated dynamicaly at runtime from the heap.How much c/c++ do you know off hand?   ;Quote:Original post by Tenshi_rdkUuurhg..please anyone !Are you sure its not releasing the memory? How do you measure your memory usage?   ;  Yes THIS does not work ! However my "BOB test;" is defined globally static.BOB test;Create_BOB(&test, 0,0, 100,100, 1, BOB_ATTR_SINGLE_FRAME, 0);Destroy_BOB(&test);I know this does not release memory , i thought it worked before but after my game loaded exactly 36 screens it started to lag ,and on my sisters slower less memory computer it started to lag earlier. So i put in the test i posted at first post in the main game loop to seeif it didn't release memory and the game started to lag after about 50sec , so it DOES NOT remove the memory.And yes I know a surface uses the "Release" command and it does use it...OK let me post the functions...IF THAT WILL HELPFirstly here's the structure and then the functionsTHANKS AGAIN GUYS !!// the blitter object structure BOBtypedef struct BOB_TYP   {   int state;// the state of the object (general)   int anim_state;// an animation state variable, up to you   int attr; // attributes pertaining to the object (general)   int x,y;  // position bitmap will be displayed at   int xv,yv;// velocity of object   int width, height;  // the width and height of the bob   int width_fill;// internal, used to force 8*x wide surfaces   int counter_1; // general counters   int counter_2;   int max_count_1;    // general threshold values;   int max_count_2;   int varsI[16]; // stack of 16 integers   float varsF[16];    // stack of 16 floats   int curr_frame;// current animation frame   int num_frames;// total number of animation frames   int curr_animation; // index of current animation   int anim_counter;   // used to time animation transitions   int anim_index;// animation element index   int anim_count_max; // number of cycles before animation   int *animations[MAX_BOB_ANIMATIONS]; // animation sequencesint bpp;//bit format   LPDIRECTDRAWSURFACE4 images[MAX_BOB_FRAMES]; // the bitmap images DD surfaces    } BOB, *BOB_PTR;int Create_BOB(BOB_PTR bob, // the bob to createint x, int y,// initial posiitonint width, int height, // size of bobint num_frames,   // number of framesint attr,    // attrsint mem_flags,    // memory flags in DD formatUSHORT color_key_value, // default color keyint bpp) // bits per pixel{// Create the BOB object, note that all BOBs // are created as offscreen surfaces in VRAM as the// default, if you want to use system memory then// set flags equal to:// DDSCAPS_SYSTEMMEMORY // for video memory you can create either local VRAM surfaces or AGP // surfaces via the second set of constants shown below in the regular expression// DDSCAPS_VIDEOMEMORY | (DDSCAPS_NONLOCALVIDMEM | DDSCAPS_LOCALVIDMEM ) DDSURFACEDESC2 ddsd; // used to create surfaceint index; // looping var// set state and attributes of BOBbob->state= BOB_STATE_ALIVE;bob->attr = attr;bob->anim_state= 0;bob->counter_1 = 0;bob->counter_2 = 0;bob->max_count_1    = 0;bob->max_count_2    = 0;bob->curr_frame= 0;bob->num_frames= num_frames;bob->bpp  = bpp;bob->curr_animation = 0;bob->anim_counter   = 0;bob->anim_index= 0;bob->anim_count_max = 0; bob->x    = x;bob->y    = y;bob->xv   = 0;bob->yv   = 0;// set dimensions of the new bitmap surfacebob->width  = width;bob->height = height;// set all images to nullfor (index=0; index<MAX_BOB_FRAMES; index++)    bob->images[index] = NULL;// set all animations to nullfor (index=0; index<MAX_BOB_ANIMATIONS; index++)    bob->animations[index] = NULL;#if 0// make sure surface width is a multiple of 8, some old version of dd like that// now, it's unneeded...bob->width_fill = ((width%8!=0) ? (8-width%8) : 0);Write_Error("\nCreate BOB: width_fill=%d",bob->width_fill);#endif// now create each surfacefor (index=0; index<bob->num_frames; index++)    {    // set to access caps, width, and height    memset(&ddsd,0,sizeof(ddsd));    ddsd.dwSize  = sizeof(ddsd);    ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;    ddsd.dwWidth  = bob->width + bob->width_fill;    ddsd.dwHeight = bob->height;    // set surface to offscreen plain    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | mem_flags;    // create the surfaces, return failure if problem    if (FAILED(lpdd->CreateSurface(&ddsd,&(bob->images[index]),NULL)))   return(0);    // set color key to default color 000    // note that if this is a 8bit bob then palette index 0 will be// transparent by default    // note that if this is a 16bit bob then RGB value 000 will be// transparent    DDCOLORKEY color_key; // used to set color key    color_key.dwColorSpaceLowValue  = color_key_value;    color_key.dwColorSpaceHighValue = color_key_value;    // now set the color key for source blitting    (bob->images[index])->SetColorKey(DDCKEY_SRCBLT, &color_key);} // end for index// return successreturn(1);} // end Create_BOBint Destroy_BOB(BOB_PTR bob){// destroy the BOB, tests if this is a real bob or a clone// if real then release all the memory, otherwise, just resets// the pointers to nullint index; // looping var// is this bob validif (!bob)    return(0);// test if this is a cloneif (bob->attr && BOB_ATTR_CLONE)    {    // null link all surfaces    for (index=0; index<MAX_BOB_FRAMES; index++)   if (bob->images[index])  bob->images[index]=NULL;    // release memory for animation sequencesfor (index=0; index<MAX_BOB_ANIMATIONS; index++)   if (bob->animations[index])  bob->animations[index]==NULL;    } // end ifelse    {    // destroy each bitmap surface    for (index=0; index<MAX_BOB_FRAMES; index++)   if (bob->images[index])  (bob->images[index])->Release();    // release memory for animation sequencesfor (index=0; index<MAX_BOB_ANIMATIONS; index++)   if (bob->animations[index])  free(bob->animations[index]);    } // end else not clone// return successreturn(1);} // end Destroy_BOBint Load_Frame_BOB16(BOB_PTR bob, // bob to load with data BITMAP_FILE_PTR bitmap, // bitmap to scan image data from int frame,  // frame to load int cx,int cy,   // cell or absolute pos. to scan image from int mode)   // if 0 then cx,cy is cell position, else  // cx,cy are absolute coords{// this function extracts a 16-bit bitmap out of a 16-bit bitmap fileDDSURFACEDESC2 ddsd;  //  direct draw surface description // is this a valid bobif (!bob)   return(0);USHORT *source_ptr,   // working pointers  *dest_ptr;// test the mode of extraction, cell based or absoluteif (mode==BITMAP_EXTRACT_MODE_CELL)   {   // re-compute x,y   cx = cx*(bob->width+1) + 1;   cy = cy*(bob->height+1) + 1;   } // end if// extract bitmap datasource_ptr = (USHORT *)bitmap->buffer + cy*bitmap->bitmapinfoheader.biWidth+cx;// get the addr to destination surface memory// set size of the structureddsd.dwSize = sizeof(ddsd);// lock the display surface(bob->images[frame])->Lock(NULL,  &ddsd,  DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,  NULL);// assign a pointer to the memory surface for manipulationdest_ptr = (USHORT *)ddsd.lpSurface;// iterate thru each scanline and copy bitmapfor (int index_y=0; index_y<bob->height; index_y++)    {    // copy next line of data to destination    memcpy(dest_ptr, source_ptr,(bob->width*2));    // advance pointers    dest_ptr   += (ddsd.lPitch >> 1);source_ptr += bitmap->bitmapinfoheader.biWidth;    } // end for index_y// unlock the surface (bob->images[frame])->Unlock(NULL);// set state to loadedbob->attr |= BOB_ATTR_LOADED;// return successreturn(1);} // end Load_Frame_BOB16;  After struggeling a bit , I FINALLY tracked down the problem !Mr andre Lamoth made a mistake it seems..I changed two lines and added one line of code , and YES ! it works BEAUTIFULLY now ! my MEMORY is FREED !!Here is the complete working Destroy_BOB() function for future people that need it !int Destroy_BOB(BOB_PTR bob){// destroy the BOB, tests if this is a real bob or a clone// if real then release all the memory, otherwise, just resets// the pointers to nullint index; // looping var// is this bob validif (bob->state != BOB_STATE_ALIVE) // <- THIS WAS CHANGED    return(0);// test if this is a cloneif (bob->attr && bob->attr == BOB_ATTR_CLONE) // <- THIS WAS CHANGED    {    // null link all surfaces    for (index=0; index<MAX_BOB_FRAMES; index++)   if (bob->images[index])  bob->images[index]=NULL;    // release memory for animation sequencesfor (index=0; index<MAX_BOB_ANIMATIONS; index++)   if (bob->animations[index])  bob->animations[index]=NULL;    } // end ifelse    {    // destroy each bitmap surface    for (index=0; index<MAX_BOB_FRAMES; index++){   if (bob->images[index]){  (bob->images[index])->Release();    }}    // release memory for animation sequencesfor (index=0; index<MAX_BOB_ANIMATIONS; index++){   if (bob->animations[index]){  free(bob->animations[index]);   }} } // end else not clonebob->state  = BOB_STATE_DEAD; // <- THIS WAS ADDED// return successreturn(1);} // end Destroy_BOB;  Your loading in a background .bmp for a bob struct.  The BOB is meant for animated sprites, if your background is changing you need to use the background loader Load/Draw_Image_Bitmap.  Also, the Destroy_bob is an older function you need to use Destroy_BOB2 which checks to see if your bob is cloned or not.  I wouldn't destroy your book but you have to realize that DD is pretty much dead and if you want to take it to the next step you have to conver to D3D.  I just finished my first real game in DD though and I would much rather have a game in DD and use the knowledge I gained to learn D3D then be overwhelmed with D3D and never have anything to show for it. I'm a big fan of Lamothe and I would question why people would say he doesn't know what he's talking about since he has like 5 or 6 books and has tons of playable demos in all of them. No he hasn't built Quake 4 but his books came out a few years ago.I think a little more information about your project would be helpful.  Do you have 600+ backgrounds? or do a few just change? If they change you can load them in at startup and just change them based on the game state.  My game uses the GPDumb engine and you can see my source code to see how I changed the background based on the state (the menu, options menu, and game running all have different backgrounds).  If you actually have 600+ backgrounds, you aren't utilizing the system correctly and you'd still have to send the 600 backgrounds to the player to have them be able to play it (they would need to be in a zip file).You can see my game's source at http://adamgames.blogspot.com and click on Bounce Tennis under my projects.   