3D (Solved) Memory leak.

I have a memory leak in my minimap object, but I can't find it, any help would be appreciated
Here is my code:
Code:
/*
I have all my objects visible from the map, set to a child of par_minimap.
*/

//CREATE EVENT FOR MINIMAP OBJECT
oSurface = surface_create(400,400);

//STEP EVENT FOR MINIMAP OBJECT
if !surface_exists(oSurface)
sw = surface_get_width(oSurface)
sh = surface_get_height(oSurface)
{
    oSurface = surface_create(400,400)
}
if surface_exists(oSurface)
{
    surface_set_target(oSurface);
    draw_clear(c_gray);
    d3d_set_projection_ortho(obj_player.x,obj_player.y,400,400,-obj_player.direction+90)
    var numObjects = instance_number(par_minimap)
    for (var i = 0; i < numObjects; i++)
    {
        var obj = instance_find(par_minimap,i);
        var _px = obj_player.x
        var _py = obj_player.y
        with(obj)
        {
            draw_sprite_ext(sprite_index,0,x+128+72, y+128+72,1,1,0,c_white,1)
        }
    }
    surface_reset_target()
}
surface_reset_target()

//DRAW GUI EVENT FOR MINIMAP OBJECT
if surface_exists(oSurface)
{
    draw_surface_ext(oSurface, 8, 8, 0.5,0.5,0,c_white,1);
    var old = draw_get_color();
    draw_set_alpha(0.5)
    draw_set_color(c_black)
    draw_rectangle(8,8,8+200,8+200,true);
    draw_rectangle(8-1,8-1,8+200+1,8+200+1,true);
    draw_set_colour(old)
    draw_set_alpha(1)
 

Mike

nobody important
GMC Elder
dont create the surface int the create event... set oSurface to -1 instead then just do this...

Code:
if !surface_exists(oSurface)
{
     oSurface = surface_create(400,400)
}

sw = surface_get_width(oSurface)
sh = surface_get_height(oSurface)

surface_set_target(oSurface);
draw_clear(c_gray);
d3d_set_projection_ortho(obj_player.x,obj_player.y,400,400,-obj_player.direction+90)
var numObjects = instance_number(par_minimap)


etc...
 
dont create the surface int the create event... set oSurface to -1 instead then just do this...

Code:
if !surface_exists(oSurface)
{
     oSurface = surface_create(400,400)
}

sw = surface_get_width(oSurface)
sh = surface_get_height(oSurface)

surface_set_target(oSurface);
draw_clear(c_gray);
d3d_set_projection_ortho(obj_player.x,obj_player.y,400,400,-obj_player.direction+90)
var numObjects = instance_number(par_minimap)


etc...
Thank you it works now.
 
Not sure what is going on here;

Code:
//STEP EVENT FOR MINIMAP OBJECT
if !surface_exists(oSurface)
sw = surface_get_width(oSurface)
sh = surface_get_height(oSurface)
{
   oSurface = surface_create(400,400)
}
If the surface doesn't exist get the width and height of the non-existant surface???

[Edit]
@Mike ninja'd me with some more reasonable code.
Already got it all sorted out.. Thanks though
 
Top