diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-06-10 08:24:21 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-06-10 11:16:41 -0700 |
commit | 69c5d844ccc36fcc23d4f2c05783ee493b3b9e00 (patch) | |
tree | 7af7ea9aa98306b5c78f9d87df8ce16ffcb369eb /text.lua | |
parent | fbad3dd2056d215397b58c49f4f9a13199cbb260 (diff) | |
download | text.love-69c5d844ccc36fcc23d4f2c05783ee493b3b9e00.tar.gz |
remove some memory leaks from rendered fragments
All signs so far seem to be that CPU is cheap for this application, but memory is expensive. It's easy to get sluggish if the GC comes on. After some experiments using https://github.com/yaukeywang/LuaMemorySnapshotDump, one source of memory leaks is rendered fragments (https://love2d.org/wiki/Text objects). I need to render text in approximately word-sized fragments to mostly break lines more intelligently at word boundaries. I've attached the files I used for my experiments (suffixed with a '.') There's definitely still a leak in fragments. The longer I edit, the more memory goes to them.
Diffstat (limited to 'text.lua')
-rw-r--r-- | text.lua | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/text.lua b/text.lua index 69b8c37..758bf5c 100644 --- a/text.lua +++ b/text.lua @@ -223,6 +223,7 @@ function Text.keychord_pressed(chord) local top2 = Text.to2(Screen_top1) top2 = Text.previous_screen_line(top2) Screen_top1 = Text.to1(top2) + Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leaks end assert(Text.le1(Screen_top1, Cursor1)) save_to_disk(Lines, Filename) @@ -423,6 +424,7 @@ function Text.pagedown() Cursor1.pos = Screen_top1.pos Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary() --? print('top now', Screen_top1.line) + Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leaks end function Text.up() @@ -662,6 +664,7 @@ function Text.snap_cursor_to_bottom_of_screen() --? print('top2 finally:', top2.line, top2.screen_line, top2.screen_pos) Screen_top1 = Text.to1(top2) --? print('top1 finally:', Screen_top1.line, Screen_top1.pos) + Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leaks end function Text.in_line(line, x,y) @@ -895,6 +898,7 @@ function Text.populate_screen_line_starting_pos(line_index) end function Text.redraw_all() + print('clearing fragments') for _,line in ipairs(Lines) do line.y = nil line.fragments = nil |