about summary refs log tree commit diff stats
path: root/main.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-10 08:24:21 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-10 11:16:41 -0700
commit69c5d844ccc36fcc23d4f2c05783ee493b3b9e00 (patch)
tree7af7ea9aa98306b5c78f9d87df8ce16ffcb369eb /main.lua
parentfbad3dd2056d215397b58c49f4f9a13199cbb260 (diff)
downloadtext.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 'main.lua')
-rw-r--r--main.lua3
1 files changed, 3 insertions, 0 deletions
diff --git a/main.lua b/main.lua
index 24d6f00..eacc8af 100644
--- a/main.lua
+++ b/main.lua
@@ -342,6 +342,7 @@ function App.keychord_pressed(chord)
       Cursor1 = Search_backup.cursor
       Screen_top1 = Search_backup.screen_top
       Search_backup = nil
+      Text.redraw_all()  -- if we're scrolling, reclaim all fragments to avoid memory leaks
     elseif chord == 'return' then
       Search_term = nil
       Search_text = nil
@@ -380,6 +381,7 @@ function App.keychord_pressed(chord)
       Cursor1 = deepcopy(src.cursor)
       Selection1 = deepcopy(src.selection)
       patch(Lines, event.after, event.before)
+      Text.redraw_all()  -- if we're scrolling, reclaim all fragments to avoid memory leaks
     end
   elseif chord == 'C-y' then
     for _,line in ipairs(Lines) do line.y = nil end  -- just in case we scroll
@@ -390,6 +392,7 @@ function App.keychord_pressed(chord)
       Cursor1 = deepcopy(src.cursor)
       Selection1 = deepcopy(src.selection)
       patch(Lines, event.before, event.after)
+      Text.redraw_all()  -- if we're scrolling, reclaim all fragments to avoid memory leaks
     end
   -- clipboard
   elseif chord == 'C-c' then