diff options
Diffstat (limited to 'src/Body.cpp')
-rw-r--r-- | src/Body.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/Body.cpp b/src/Body.cpp index ced71fa..61d319a 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -10,6 +10,7 @@ #include <SFML/OpenGL.hpp> #include <assert.h> #include <cmath> +#include <malloc.h> static const sf::Color front_color(32, 36, 42); static const sf::Color back_color(33, 35, 37); @@ -140,6 +141,12 @@ namespace QuickMedia { loading_icon.setOrigin(loading_icon_size.x * 0.5f, loading_icon_size.y * 0.5f); } + Body::~Body() { + item_thumbnail_textures.clear(); + items.clear(); + malloc_trim(0); + } + // TODO: Make this work with wraparound enabled? // TODO: For plugins with different sized body items this can be weird, because after scrolling down thumbnails could load and they could move items up/down until we see items we haven't seen bool Body::select_previous_page() { @@ -326,6 +333,7 @@ namespace QuickMedia { void Body::clear_cache() { clear_text_cache(); clear_thumbnails(); + malloc_trim(0); } void Body::clear_text_cache() { @@ -749,10 +757,12 @@ namespace QuickMedia { mouse_left_clicked = false; for(auto it = item_thumbnail_textures.begin(); it != item_thumbnail_textures.end();) { - if(!it->second->referenced) + if(!it->second->referenced) { it = item_thumbnail_textures.erase(it); - else + loaded_textures_changed = true; + } else { ++it; + } } // TODO: Only do this for items that are not visible, do not loop all items. @@ -764,6 +774,11 @@ namespace QuickMedia { if(body_item->embedded_item && elapsed_time_sec - body_item->embedded_item->last_drawn_time >= 1.5) clear_body_item_cache(body_item->embedded_item.get()); } + + if(loaded_textures_changed) { + loaded_textures_changed = false; + malloc_trim(0); + } } void Body::update_dirty_state(BodyItem *body_item, float width) { @@ -1162,6 +1177,7 @@ namespace QuickMedia { item_thumbnail->image.reset(); item_thumbnail->loading_state = LoadingState::APPLIED_TO_TEXTURE; item_thumbnail->texture_applied_time.restart(); + loaded_textures_changed = true; } } |