@@ -104,7 +104,10 @@ function plan_elementwise_trinary(
104104 plan_pref = Ref {cutensorPlanPreference_t} ()
105105 cutensorCreatePlanPreference (handle (), plan_pref, algo, jit)
106106
107- CuTensorPlan (desc[], plan_pref[]; workspacePref= workspace)
107+ plan = CuTensorPlan (desc[], plan_pref[]; workspacePref= workspace)
108+ cutensorDestroyOperationDescriptor (desc[])
109+ cutensorDestroyPlanPreference (plan_pref[])
110+ return plan
108111end
109112
110113function elementwise_binary_execute! (
@@ -186,7 +189,10 @@ function plan_elementwise_binary(
186189 plan_pref = Ref {cutensorPlanPreference_t} ()
187190 cutensorCreatePlanPreference (handle (), plan_pref, algo, jit)
188191
189- CuTensorPlan (desc[], plan_pref[]; workspacePref= workspace)
192+ plan = CuTensorPlan (desc[], plan_pref[]; workspacePref= workspace)
193+ cutensorDestroyOperationDescriptor (desc[])
194+ cutensorDestroyPlanPreference (plan_pref[])
195+ return plan
190196end
191197
192198function permute! (
@@ -253,7 +259,10 @@ function plan_permutation(
253259 plan_pref = Ref {cutensorPlanPreference_t} ()
254260 cutensorCreatePlanPreference (handle (), plan_pref, algo, jit)
255261
256- CuTensorPlan (desc[], plan_pref[]; workspacePref= workspace)
262+ plan = CuTensorPlan (desc[], plan_pref[]; workspacePref= workspace)
263+ cutensorDestroyOperationDescriptor (desc[])
264+ cutensorDestroyPlanPreference (plan_pref[])
265+ return plan
257266end
258267
259268function contract! (
@@ -340,7 +349,10 @@ function plan_contraction(
340349 plan_pref = Ref {cutensorPlanPreference_t} ()
341350 cutensorCreatePlanPreference (handle (), plan_pref, algo, jit)
342351
343- CuTensorPlan (desc[], plan_pref[]; workspacePref= workspace)
352+ plan = CuTensorPlan (desc[], plan_pref[]; workspacePref= workspace)
353+ cutensorDestroyOperationDescriptor (desc[])
354+ cutensorDestroyPlanPreference (plan_pref[])
355+ return plan
344356end
345357
346358function reduce! (
@@ -415,5 +427,8 @@ function plan_reduction(
415427 plan_pref = Ref {cutensorPlanPreference_t} ()
416428 cutensorCreatePlanPreference (handle (), plan_pref, algo, jit)
417429
418- CuTensorPlan (desc[], plan_pref[]; workspacePref= workspace)
430+ plan = CuTensorPlan (desc[], plan_pref[]; workspacePref= workspace)
431+ cutensorDestroyOperationDescriptor (desc[])
432+ cutensorDestroyPlanPreference (plan_pref[])
433+ return plan
419434end
0 commit comments