Texture painting modal fills up the memory

I have a texture painting modal which uses bpy.ops.image_paint() . The issue is that it the memory usage goes up incredibly fast when painting with it. This is resolved when the modal is ended, then the memory clears again. Here’s a simplified version which also has this problem:

import bpy

class TEST_OT_PaintModal(bpy.types.Operator):
    bl_idname = "test.paint_modal"
    bl_label = "Paint Modal"
    bl_description = "Starts the pant modal"
    bl_options = {"REGISTER","UNDO"}

    def paint_stroke(self, stroke):

        bpy.data.brushes["TexDraw"].color = (1,0,0)

        #paint strokes
        bpy.ops.paint.image_paint(self.context_override,
        stroke = [{
            "name": "defaultStroke",
            "pen_flip": False,
            "pressure": 1.0,
            "is_start": True, 
            "location":(0,0,0), 
            "mouse":stroke,
            "time": 1.0,
            "size": bpy.context.scene.tool_settings.unified_paint_settings.size
        }])


    def modal(self, context, event):
        #paint
        if event.type == 'MOUSEMOVE' and self.painting:
            stroke = (event.mouse_region_x,event.mouse_region_y)
            self.paint_stroke(stroke)

        #stop painting
        elif event.type == 'LEFTMOUSE' and event.value == "RELEASE" and self.painting:
            self.painting = False
            bpy.context.area.tag_redraw()

        #start painting
        elif event.type == "LEFTMOUSE" and event.value =="PRESS" and event.shift and not self.painting:
            self.painting = True

        #finish modal
        elif event.type == "ESC" or event.type == "RET":
            return {'FINISHED'}

        return {'PASS_THROUGH'}

    def invoke(self, context, event):

        #set multipaint prop defaults
        self.painting = False
        self.context_override = bpy.context.copy()

        #start multipaint
        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}


if __name__ == "__main__":
    bpy.utils.register_class(TEST_OT_PaintModal)

Does someone know if I’m doing something wrong or if this is a blender issue?
(This is a repost of this question on StackExchange: https://blender.stackexchange.com/questions/172216/texture-painting-modal-fills-up-the-memory)