This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new 9c9524caeb6 branch-4.0:[improvement](storage) Release unused memory 
earlier, rather than leaving it to the memory pool for guaranteed release 
(#62185)
9c9524caeb6 is described below

commit 9c9524caeb608eeb5f68ea85556e0fd7b2e727c6
Author: 黄瑞鑫 <[email protected]>
AuthorDate: Wed Apr 15 12:33:03 2026 +0800

    branch-4.0:[improvement](storage) Release unused memory earlier, rather 
than leaving it to the memory pool for guaranteed release (#62185)
    
    ### What problem does this PR solve?
    
    Issue Number: close #xxx
    
    Related PR: #xxx
    
    Problem Summary:
    
    pick from https://github.com/apache/doris/pull/57215
    
    ### Release note
    
    None
    
    ### Check List (For Author)
    
    - Test <!-- At least one of them must be included. -->
        - [ ] Regression test
        - [ ] Unit Test
        - [ ] Manual test (add detailed scripts or steps below)
        - [ ] No need to test or manual test. Explain why:
    - [ ] This is a refactor/code format and no logic has been changed.
            - [ ] Previous test can cover this change.
            - [ ] No code files have been changed.
            - [ ] Other reason <!-- Add your reason?  -->
    
    - Behavior changed:
        - [ ] No.
        - [ ] Yes. <!-- Explain the behavior change -->
    
    - Does this need documentation?
        - [ ] No.
    - [ ] Yes. <!-- Add document PR link here. eg:
    https://github.com/apache/doris-website/pull/1214 -->
    
    ### Check List (For Reviewer who merge this PR)
    
    - [ ] Confirm the release note
    - [ ] Confirm test cases
    - [ ] Confirm document
    - [ ] Add branch pick label <!-- Add branch pick label that this PR
    should merge into -->
---
 be/src/olap/memtable.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/be/src/olap/memtable.cpp b/be/src/olap/memtable.cpp
index a5481d39a4f..ba55aa69a5c 100644
--- a/be/src/olap/memtable.cpp
+++ b/be/src/olap/memtable.cpp
@@ -484,7 +484,7 @@ void MemTable::_clear_row_agg(RowInBlock* row) {
         row->remove_init_agg();
     }
 }
-
+// only in `to_block` the `is_final` flag will be true, in other cases, it 
will be false
 template <bool is_final, bool has_skip_bitmap_col>
 void MemTable::_aggregate() {
     SCOPED_RAW_TIMER(&_stat.agg_ns);
@@ -509,10 +509,15 @@ void MemTable::_aggregate() {
                 }
                 _stat.merged_rows++;
                 
_aggregate_two_row_in_block<has_skip_bitmap_col>(mutable_block, cur_row, 
prev_row);
+                // Clean up aggregation state of the merged row to avoid 
memory leak
+                if (cur_row) {
+                    _clear_row_agg(cur_row);
+                }
             } else {
                 prev_row = cur_row;
                 if (!temp_row_in_blocks.empty()) {
-                    // no more rows to merge for prev row, finalize it
+                    // The rows from the previous batch of _row_in_blocks have 
been merged into temp_row_in_blocks,
+                    // now call finalize to write the aggregation results into 
_output_mutable_block.
                     
_finalize_one_row<is_final>(temp_row_in_blocks.back().get(), block_data,
                                                 row_pos);
                 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to