-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix csharp cscvrptw example. Protect callbacks from GC. #5
Fix csharp cscvrptw example. Protect callbacks from GC. #5
Conversation
examples/csharp/cscvrptw.cs
Outdated
//protect callbacks from the GC | ||
GC.KeepAlive(manhattan_callback); | ||
GC.KeepAlive(demand_callback); | ||
for (int cost_callback_index = 0; cost_callback_index < cost_callbacks.Length; cost_callback_index++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"{" should be at the end on line for consistency
b0098bc
to
5073757
Compare
//protect callbacks from the GC | ||
GC.KeepAlive(manhattan_callback); | ||
GC.KeepAlive(demand_callback); | ||
for (int cost_callback_index = 0; cost_callback_index < cost_callbacks.Length; cost_callback_index++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mizux Fixed
"{" should be at the end on line for consistenc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks !
AT-8842: Fix `go.Dockerfile` for export
When we invoke SolveWithParameters of RoutingModel CLR GC can start collecting.
If it's happens, we get exception when callbacks invoked because GC think that delegates won't be used and clear objects.
Exception: CallbackOnCollectedDelegate
A callback was made on a garbage collected delegate of type 'Google.OrTools!Google.OrTools.ConstraintSolver.NodeEvaluator2+SwigDelegateNodeEvaluator2_0::Invoke'. This may cause application crashes, corruption and
data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.
For fix use GC.KeepAlive method.
Here example of this solution with delegates and unmanaged code.
https://msdn.microsoft.com/en-us/library/system.gc.keepalive(v=vs.110).aspx