CudaText: markers memory leak

@Alexey-T run 2nd test (press “2” key) or 3rd test (“3” key) and watch memory consumption of cudatext.exe

every press of 2 key increases memory by 1-2mb every press of 3 key increases memory by 3-4mb

Note: markers count is constant 1750 (they are removed by MARKERS_DELETE_ALL and added again) so it is very strange why memory consumption is increasing at all. it must stay barely unchanged.

from cudatext import *
import cudatext_cmd as cmds
from itertools import product
import random
import time

processing = False

class Command:
    def run(self):
        h = dlg_proc(0, DLG_CREATE)
        dlg_proc(h, DLG_PROP_SET, prop={'border': DBORDER_SIZE,'w': 1000,'h': 600, 'keypreview': True, 'on_key_press': self.form_key_press})
        n = dlg_proc(h, DLG_CTL_ADD, 'editor')
        dlg_proc(h, DLG_CTL_PROP_SET, index=n, prop={ 'name': 'memo','a_r': ('', ']'), 'a_b': ('', ']'), 'font_size': 11 })
        self.h_dlg = h

        self.memo = Editor(dlg_proc(h, DLG_CTL_HANDLE, index=n))

        self.memo.set_text_all(('F'*70+'\n')*25)
        self.memo.set_prop(PROP_RO, True)

        #self.memo.attr(MARKERS_DELETE_BY_POS, x=0, y=0)

        dlg_proc(h, DLG_SHOW_NONMODAL)

    def form_key_press(self, id_dlg, id_ctl, data='', info=''):3
        global processing
        if processing:
            return
        processing = True

        start = time.time()
        markers_added = 0
        top = 0
        self.memo.set_prop(PROP_RO, False)

        print('start test', chr(id_ctl))

        if id_ctl == ord('1'):
            self.memo.attr(MARKERS_SET_DUPS, tag=1) # test 1
        elif id_ctl == ord('2'):
            self.memo.attr(MARKERS_SET_DUPS, tag=0) # test 2
        elif id_ctl == ord('3'):
            self.memo.attr(MARKERS_SET_DUPS, tag=0) # test 3
            self.memo.cmd(cmds.cCommand_GotoTextEnd)
            x, y = self.memo.get_carets()[0][0:2]
            self.memo.insert(x, y, ('F'*70+'\n')*25)
            top = y
        else:
            self.memo.set_prop(PROP_RO, True)
            processing = False
            return

        self.memo.set_prop(PROP_RO, True)
        
        self.memo.attr(MARKERS_DELETE_ALL)

        count = 10
        while count > 0:
            markers_added = 0
            for x, y in product(range(70), range(25)):
                self.memo.attr(MARKERS_ADD, x=x, y=y+top, len=1, color_font=random.randint(0,255), color_bg=random.randint(0,255))
                markers_added += 1
            count -= 1

            #we can repaint memo every iteration here, but...
            #self.memo.cmd(cmds.cmd_RepaintEditor) # not working
            #app_idle() # repaints, but if I hold key it causes recursion into "form_key_press"?? how to avoid it?
            self.memo.action(EDACTION_UPDATE)

        end = time.time()
        t = (end-start)*1000
        marker_count = len(self.memo.attr(MARKERS_GET))

        # print test results
        if id_ctl == ord('1') or id_ctl == ord('2'):
            print('end. time={:.0f} ms, trash markers={}'.format(t, marker_count-markers_added))
        else:
            print('end. time={:.0f} ms, markers added/total={}/{}'.format(t, markers_added, marker_count))


        # update caption
        dlg_proc(self.h_dlg, DLG_PROP_SET, prop={
            'cap': '{} markers total, time={:.0f}'.format( marker_count, t )
        })

        processing = False

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

updated ExTerminal in addons.