sdl memory leak!

hello! i have a memory leak in my game and i can't find the problem.
here is my code(its a mess)
:
main:
#include "game.h"


int main(int argc, char *argv[])
{
game_obj = new game();
game_obj->onExecute();
return 0;
}



game.h :

#include <iostream>
#include <SDL.h>
#include <SDL_image.h>

class game
{
public:
game();
void onExecute();
void OnInit();
void LoadContent();
void OnEvent(SDL_Event* Event);
void OnLoop();
void OnRender();
void Cleanup();

private:
bool Running = true;
int x, y;
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Event *Event;
SDL_Texture *back_img;
SDL_Texture *player_img;
SDL_Texture *enemy_img;
SDL_Rect R_back;
SDL_Rect R_player;
SDL_Rect R_enemy;


};





game.cpp:

#include "game.h"


game::game()
{
Event = new SDL_Event();
x = 120;
y = 295;
}


void game::onExecute()
{
OnInit();
while(Running == true)
{
OnEvent(Event);
}
Cleanup();

}




oninit:

#include "game.h"

void game::OnInit()
{
SDL_Init(SDL_INIT_EVERYTHING);
window = SDL_CreateWindow("first game",150,150,640,480,SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED);

}

loadcontent:

#include "game.h"

void game::LoadContent()
{
int w = 0;
int h = 0;
back_img = IMG_LoadTexture(renderer,"game images/cityback.bmp");
SDL_QueryTexture(back_img,NULL,NULL,&w,&h);
R_back.x = 0; R_back.y = 0; R_back.w = 640; R_back.h = 480;

player_img = IMG_LoadTexture(renderer,"game images/chara.gif");
SDL_QueryTexture(player_img,NULL,NULL,&w,&h); //get x and y
R_player.x = x; R_player.y = y; R_player.w = w - 20; R_player.h = h - 23 ;

enemy_img = IMG_LoadTexture(renderer,"game images/alien game.gif");
SDL_QueryTexture(enemy_img,NULL,NULL,&w,&h);
R_enemy.x = 500; R_enemy.y = 267; R_enemy.w = w; R_enemy.h = h;



}




onrender:


void game::OnRender()
{
SDL_PollEvent(Event);
SDL_SetRenderDrawColor(renderer,0,0,0,0);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer,back_img,NULL,&R_back);
SDL_RenderCopy(renderer,player_img,NULL,&R_player);
SDL_RenderCopy(renderer,enemy_img,NULL,&R_enemy);
SDL_free(back_img);
SDL_free(player_img);
SDL_free(enemy_img);

SDL_RenderPresent(renderer);
}




onevent:

#include "game.h"

void game::OnEvent(SDL_Event *Event)
{
while ((Event->type != SDL_QUIT) && (Running != false))
{
if (Event->type == SDL_KEYDOWN)
{
switch(Event->key.keysym.sym)
{
case SDLK_RIGHT: x += 4; break;
case SDLK_LEFT: x -= 4; break;
case SDLK_ESCAPE: Running = false; break; break;
}

}
LoadContent();
OnRender();
SDL_free(Event);

}
Cleanup();
}




cleanup:

#include "game.h"

void game::Cleanup()
{
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_DestroyTexture(back_img);
SDL_DestroyTexture(player_img);
SDL_DestroyTexture(enemy_img);
delete Event;
SDL_Quit();
IMG_Quit();
}



please hlp me, it are basic lines of code!
game_obj = new game(); where do you delete this in the main function?

Also why not use a destructor instead of
1
2
3
4
5
6
7
8
9
10
11
void game::Cleanup()
{
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_DestroyTexture(back_img);
SDL_DestroyTexture(player_img);
SDL_DestroyTexture(enemy_img);
delete Event;
SDL_Quit();
IMG_Quit();
}
My first question would be how you determined a memory leak exists.
Topic archived. No new replies allowed.