Dispose Scalars implicitly created in Tensor operators#1434
Conversation
|
@dotnet-policy-service agree |
273f174 to
ff6ffd7
Compare
ff6ffd7 to
3778ec6
Compare
|
Is there anything I need to do for this to be merged? |
3778ec6 to
6c5156f
Compare
6c5156f to
a714ab7
Compare
|
|
|
@hiyuh if you want to make a pull request onto my branch with your additions, I'd happily merge it so that they can be part of the review for this pull request. |
|
@ds5678 |
3692c79 to
1a3a0a7
Compare
1a3a0a7 to
cdbfd62
Compare
334f8d1 to
a8c4116
Compare
a8c4116 to
ed22ff4
Compare
b0c8292 to
931bf05
Compare
931bf05 to
31c6361
Compare
31c6361 to
aae5149
Compare
There was a problem hiding this comment.
Pull request overview
This pull request updates TorchSharp’s Tensor arithmetic operator overloads that accept primitive numeric operands so that the implicitly created Scalar instances are disposed immediately (via using), rather than being left for finalization/GC.
Changes:
- Wrap primitive operands (
int,long,float,double) inusing Scalar scalar = ...;withinTensoroperator overloads. - Route primitive-based operators through existing
Tensor/Scalaroperator overloads to avoid leaking nativeScalarhandles. - Apply the pattern consistently for
+,*,-,/, and%operator overloads.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request modifies the
Tensoroperators involving primitives to immediately dispose theScalarobject they create, rather than waiting for the garbage collector.