Error when register_module in Debug mode but not in Release moode

I’m using Visual Studio 2022 in Windows 10, following code generate a Reading Access error:

#include <iostream>
#include <torch/torch.h>

class MyLinear : public torch::nn::Module {
	torch::nn::Linear linear;
	MyLinear() :linear(torch::nn::Linear(3, 1)) { register_module("linear", linear); };

int main() {
	MyLinear linear;


If I switch to Release mode, then there is no problem. The Debug and Release mode use the same torch library (nightly build).