Results 1 to 9 of 9

Thread: Out of Memory error even when bitmap is released?

  1. #1
    Join Date
    May 2008
    Location
    Canada
    Posts
    665
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default Out of Memory error even when bitmap is released?

    Heya,

    I was using this function and got an out of memory error on this line after running it for awhile:
    tmpBitmap := bitmapFromClient(x1,y1,x2,y2);

    I thought I released it? But did I miss something?

    Thanks in advance

    Simba Code:
    Function GetBitmapText(x1,y1,x2,y2):String;
    var tmpBitmap:Integer;
    var tmpMufasa:TMufasaBitmap;
    var tmpString:String;
    begin

      tmpBitmap := bitmapFromClient(x1,y1,x2,y2);
      tmpMufasa := GetMufasaBitmap(tmpBitmap);
      tmpMufasa := Resize(tmpMufasa);

      ThresholdAdaptiveBitmap(tmpBitmap, 0, 255, false, TM_Mean, 18);

      tmpString := Tess_GetText(tmpMufasa);
      Freebitmap(tmpBitmap);
      Result := tmpString;

    end;

  2. #2
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    You probably need to free the TMufasaBitmap as well. Try something like this
    Simba Code:
    tmpMufasa := getMufasaBitmap(bitmapFromClient(x1, y1, x2, y2));
    ...
    tmpMufasa.free();

  3. #3
    Join Date
    May 2008
    Location
    Canada
    Posts
    665
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    Worked great! Though this is not in the documentation.

    Quote Originally Posted by Citrus View Post
    You probably need to free the TMufasaBitmap as well. Try something like this
    Simba Code:
    tmpMufasa := getMufasaBitmap(bitmapFromClient(x1, y1, x2, y2));
    ...
    tmpMufasa.free();

  4. #4
    Join Date
    May 2008
    Location
    Canada
    Posts
    665
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    wait. It didn't work great.

    Simba Code:
    Freebitmap(tmpBitmap);
    tmpMufasa.free();
    Causes access violation.


    Simba Code:
    tmpMufasa.free();
    Freebitmap(tmpBitmap);
    tmpBitmap already doesn't exist.



    Simba Code:
    tmpMufasa.free();
    Still causes memory leaks

  5. #5
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Does Resize create a copy of the TMufasaBitmap? If it does you are losing a reference when you overwrite the tmpMufasa variable.

  6. #6
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Yeah, I'm not getting any leaks when I test it myself. It must be your resize function. Did you try TMufasaBitmap.ResizeEx() ?

  7. #7
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Simba Code:
    function GetBitmapText(x1,y1,x2,y2):String;
    var tmpBitmap:Integer;
    var tmpMufasa:TMufasaBitmap;
    var tmpString:String;
    begin

      tmpBitmap := bitmapFromClient(x1,y1,x2,y2);   //creates 1 bitmap
      tmpMufasa := GetMufasaBitmap(tmpBitmap);      //get the actual underlying bitmap (it's the same as tmpBitmap atm)
      tmpMufasa := Resize(tmpMufasa);               //Idk of any such method, but as you assign some result.. then you are likely copying..

      ThresholdAdaptiveBitmap(tmpBitmap, 0, 255, false, TM_Mean, 18);  //runs threshold on the OLD bitmap.. not the new resized one

      tmpString := Tess_GetText(tmpMufasa); //Gets text from the new resize one, which is not thresholded...
      Freebitmap(tmpBitmap);                //free the first bitmap (the thresholded one) -> not the resized one
      Result := tmpString;

    end;

    This is pretty much how it should be:
    Simba Code:
    function RecognizeTextAt(x1,y1,x2,y2: Int32; Scale:Double; ThresholdMod:Int32):String;
    var
      clientBmp:TMufasaBitmap;
    begin
      clientBmp := GetMufasaBitmap(BitmapFromClient(x1,y1,x2,y2));                     //get client image and get the actual mufasa bitmap directly
      clientBmp.ResizeEx(RM_Bilinear, Round((x2-x1+1)*Scale), Round((y2-y1+1)*Scale)); //resize that bitmap without copying
      clientBmp.ThresholdAdaptive(0, 255, False, TM_Mean, ThresholdMod);               //threshold it, again without copying

      //assuming it takes a mufasabitmap (I don't use SRL-6 at all)
      Result := Tess_GetText(clientBmp);                                               //recognize the text
      //Result := Tess_GetText(clientBmp.GetIndex()); //if not
      clientBmp.Free();                                                                //free
    end;

    var text:String;
    begin
      text := RecognizeTextAt(someBounds..., 3.5, 18);
    end.
    Last edited by slacky; 03-23-2017 at 04:57 AM.
    !No priv. messages please

  8. #8
    Join Date
    May 2008
    Location
    Canada
    Posts
    665
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    Quote Originally Posted by tls View Post
    Does Resize create a copy of the TMufasaBitmap? If it does you are losing a reference when you overwrite the tmpMufasa variable.
    It did! Fixed it

    Quote Originally Posted by Citrus View Post
    Yeah, I'm not getting any leaks when I test it myself. It must be your resize function. Did you try TMufasaBitmap.ResizeEx() ?
    I didn't think to open that... that would've been a useful function to use!

    Quote Originally Posted by slacky View Post
    ...
    This is pretty much how it should be:
    Simba Code:
    function RecognizeTextAt(x1,y1,x2,y2: Int32; Scale:Double; ThresholdMod:Int32):String;
    var
      clientBmp:TMufasaBitmap;
    begin
      clientBmp := GetMufasaBitmap(BitmapFromClient(x1,y1,x2,y2));                     //get client image and get the actual mufasa bitmap directly
      clientBmp.ResizeEx(RM_Bilinear, Round((x2-x1+1)*Scale), Round((y2-y1+1)*Scale)); //resize that bitmap without copying
      clientBmp.ThresholdAdaptive(0, 255, False, TM_Mean, ThresholdMod);               //threshold it, again without copying

      //assuming it takes a mufasabitmap (I don't use SRL-6 at all)
      Result := Tess_GetText(clientBmp);                                               //recognize the text
      //Result := Tess_GetText(clientBmp.GetIndex()); //if not
      clientBmp.Free();                                                                //free
    end;

    var text:String;
    begin
      text := RecognizeTextAt(someBounds..., 3.5, 18);
    end.
    That looks more proper in everyway xD.

  9. #9
    Join Date
    May 2008
    Location
    Canada
    Posts
    665
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    @Slacky

    I think your function should go into SRL, what do you think?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •