Skip to content

Commit

Permalink
[darwin-framework-tool] Add some autorelease pools to CHIPCommandBrid…
Browse files Browse the repository at this point in the history
…ge::Run to make the memory graph cleaner (#36046)
  • Loading branch information
vivien-apple authored and pull[bot] committed Nov 29, 2024
1 parent 3910fae commit 4b3c024
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,40 @@

CHIP_ERROR CHIPCommandBridge::Run()
{
ChipLogProgress(chipTool, "Running Command");
ReturnErrorOnFailure(MaybeSetUpStack());
SetIdentity(mCommissionerName.HasValue() ? mCommissionerName.Value() : kIdentityAlpha);
// In interactive mode, we want to avoid memory accumulating in the main autorelease pool,
// so we clear it after each command.
@autoreleasepool {
ChipLogProgress(chipTool, "Running Command");
// Although the body of `Run` is within its own autorelease pool, this code block is further wrapped
// in an additional autorelease pool. This ensures that when the memory dump graph command is used directly,
// we can verify there’s no additional noise from the autorelease pools—a kind of sanity check.
@autoreleasepool {
ReturnErrorOnFailure(MaybeSetUpStack());
}
SetIdentity(mCommissionerName.HasValue() ? mCommissionerName.Value() : kIdentityAlpha);

{
std::lock_guard<std::mutex> lk(cvWaitingForResponseMutex);
mWaitingForResponse = YES;
}
{
std::lock_guard<std::mutex> lk(cvWaitingForResponseMutex);
mWaitingForResponse = YES;
}

ReturnLogErrorOnFailure(RunCommand());
ReturnLogErrorOnFailure(RunCommand());

auto err = StartWaiting(GetWaitDuration());
auto err = StartWaiting(GetWaitDuration());

bool deferCleanup = (IsInteractive() && DeferInteractiveCleanup());
bool deferCleanup = (IsInteractive() && DeferInteractiveCleanup());

Shutdown();
Shutdown();

if (deferCleanup) {
sDeferredCleanups.insert(this);
} else {
Cleanup();
}
MaybeTearDownStack();
if (deferCleanup) {
sDeferredCleanups.insert(this);
} else {
Cleanup();
}
MaybeTearDownStack();

return err;
return err;
}
}

CHIP_ERROR CHIPCommandBridge::GetPAACertsFromFolder(NSArray<NSData *> * __autoreleasing * paaCertsResult)
Expand Down

0 comments on commit 4b3c024

Please sign in to comment.