A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Does BitmapData.dispose() remove memory occupied by its Bitmap

  1. #1
    Member
    Join Date
    May 2009
    Posts
    57

    Does BitmapData.dispose() remove memory occupied by its Bitmap

    Hi there,
    This is my scenario
    1: I upload an image
    2: Without altering it,I make a copy of it and use it display to users in resized format
    note: I won't display the original image.
    3:Now when user deletes the resized image,i need to delete the image loaded as bitmap i.e. the original image which i won't be displaying

    For that I used bitmap.bitmapData.dispose() method.But,it doesn't free up the memory taken by the bitmap.
    For instance at initial state the memory usage is 58 Mb and upon loading 3 images the size increases to 87 Mb.
    And when I delete all the images the size decreases to 81 MB only.
    So,I feel the loaded bitmap is not completely removed.
    Any idea what should I do

  2. #2
    Some bloke
    Join Date
    Jan 2007
    Location
    Villa Rica, GA
    Posts
    9

    Question Removing or recycling the bitmapdata?

    Are you trying to get rid of or recycle the bitmapdata? Because what's happening is it's clearing out the bitmapdata. The bitmapdata object inside the bitmap object is still there it's just cleared.

  3. #3
    Member
    Join Date
    May 2009
    Posts
    57

    I am not trying to recycle

    Hi Cinema,
    I am trying to completely remove the bitmap from my application or to say from memory.

    P.S.: My application is online tshirt customizer where user is able to upload his/her image.
    -> A clone of uploaded image is made
    ->This cloned image undergoes scaling and cloned image is seen by the user
    ->I have added original image in this format loader.content as Bitmap
    ->And I need to free the memory occupied by this original image
    Last edited by laaptu; 06-07-2010 at 02:39 AM.

  4. #4
    Some bloke
    Join Date
    Jan 2007
    Location
    Villa Rica, GA
    Posts
    9

    Lightbulb I know what you are trying to do now

    To get rid of the bitmap object you are to have to make it unreachable* by removing all references to it; set the variable to null - if that is the only reference. Then you wait for garbage collection to remove it. However it's better to recycle frequently used objects than wait for them to be destroyed.

    *Manually memory management, like destructors found in C/C++, aren't in scripting language likes AS3, at least where we can use it. You have to deal with automatic memory management or ubiquitously know as garbage collection.

  5. #5
    Member
    Join Date
    May 2009
    Posts
    57

    This method works well so far

    While going through Garbage collector in Actionscript 3,I came across an article at

    http://www.craftymind.com/2008/04/09...pt-3-with-air/

    And using this method ,I was able to free the memory significantly.
    For instance
    ->Initial memory taken by my app was 58 Mb
    ->On addition of 3 images the memory size went to 87 Mb
    ->And using above process along with bitmapData.dispose() ,when I removed the 3 images the size went down to 70 Mb

    Though I couldn't go back to range of 58 Mb, I could get significant memory in comparison to my previous implementation

  6. #6
    Some bloke
    Join Date
    Jan 2007
    Location
    Villa Rica, GA
    Posts
    9

    Unhappy Linked me to a 404 page

    How exactly did you do it, I'm very curious.

  7. #7
    Member
    Join Date
    May 2009
    Posts
    57

    Try this again

    First of all my simple method
    Code:
    bitmap.bitmapData.dispose();
    bitmap =null;
    Then running the code described in this webpage

    http://www.craftymind.com/2008/04/09...pt-3-with-air/

  8. #8
    Some bloke
    Join Date
    Jan 2007
    Location
    Villa Rica, GA
    Posts
    9

    Thumbs up Excellent

    Thanks for the share glad everything worked out for you, except for the 12MB lost somewhere.

  9. #9
    Member
    Join Date
    May 2009
    Posts
    57

    Thanks

    I will be still chasing that 12 Mb and if anything comes noteworthy I will surely post it here

  10. #10
    Member
    Join Date
    May 2009
    Posts
    57

    Forcing Garbage Collector restriction

    To all,
    System.gc()

    works only on Flash Player debugger version and on AIR app.
    So forcing garbage collector is restricted for flash player standalone version.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center