Skip to content

Commit

Permalink
Use shrink_to_fit instead of = {} assignment
Browse files Browse the repository at this point in the history
I'm no C++ expert, but it looks like `vec = {}` is not guaranteed to
release memory.
  • Loading branch information
rui314 committed Jan 11, 2025
1 parent 0ca543e commit 8cd5574
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/input-sections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ void MergeableSection<E>::resolve_contents(Context<E> &ctx) {
fragments.push_back(parent.insert(ctx, get_contents(i), hashes[i], p2align));

// Reclaim memory as we'll never use this vector again
hashes = {};
hashes.clear();
hashes.shrink_to_fit();
}

using E = MOLD_TARGET;
Expand Down
3 changes: 2 additions & 1 deletion src/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ void create_output_sections(Context<E> &ctx) {
osec->shdr.sh_flags = osec->sh_flags;
osec->is_relro = is_relro(*osec);
osec->members = flatten(osec->members_vec);
osec->members_vec = {};
osec->members_vec.clear();
osec->members_vec.shrink_to_fit();
}

// Add output sections and mergeable sections to ctx.chunks
Expand Down

0 comments on commit 8cd5574

Please sign in to comment.