@@ -713,6 +713,9 @@ Error Method::resolve_operator(
713713 }
714714 TensorMeta* meta = allocator->allocateList <TensorMeta>(n_args);
715715 if (meta == nullptr ) {
716+ if (allocator == memory_manager_->temp_allocator ()) {
717+ memory_manager_->temp_allocator ()->reset ();
718+ }
716719 return Error::MemoryAllocationFailed;
717720 }
718721
@@ -726,6 +729,9 @@ Error Method::resolve_operator(
726729 executorch::aten::DimOrderType* dim_order_ptr =
727730 allocator->allocateList <executorch::aten::DimOrderType>(tensor.dim ());
728731 if (dim_order_ptr == nullptr ) {
732+ if (allocator == memory_manager_->temp_allocator ()) {
733+ memory_manager_->temp_allocator ()->reset ();
734+ }
729735 return Error::MemoryAllocationFailed;
730736 }
731737 size_t size = tensor.dim ();
@@ -751,9 +757,18 @@ Error Method::resolve_operator(
751757 " Missing operator: [%" ET_PRIssize_t " ] %s" ,
752758 static_cast <ssize_t >(op_index),
753759 operator_name);
760+ if (allocator == memory_manager_->temp_allocator ()) {
761+ memory_manager_->temp_allocator ()->reset ();
762+ }
754763 return op_function.error ();
755764 }
756765 kernels[kernel_index] = op_function.get ();
766+
767+ // If we used the temp allocator here, reset it.
768+ if (allocator == memory_manager_->temp_allocator ()) {
769+ memory_manager_->temp_allocator ()->reset ();
770+ }
771+
757772 return Error::Ok;
758773}
759774
@@ -1547,6 +1562,9 @@ Error Method::execute() {
15471562 i);
15481563 }
15491564 ET_LOG (Debug, " Executing method: %s." , method_meta ().name ());
1565+ if (temp_allocator_ != nullptr ) {
1566+ temp_allocator_->reset ();
1567+ }
15501568
15511569 // Chains are executed sequentially today, but future async designs may
15521570 // branch and run many in parallel or out of order.
0 commit comments