Out of Memory Sparse Matrix

Good evening,
I’m new to Julia and I was trying to rewrite a MATLAB code, to speed it up. The main problem is that the code generates an “Out of Memory” error and I don’t understand why.
Outside a while loop I define

A=kron(J,Kx)+kron(Ay,J);
Id=I(N*N); #I use sparse matrices package
K=Id+(2.*D.*dt.*theta).*A;
R_app=Id-2.*D.*dt.*(1-theta).*A;

where J, Kx, Ay are sparse matrices, dt, D and theta are scalars and N is integer. Here everything works fast, without any errors.
Then, inside the while loop, I update K and R_app (due to the change of dt)

K=Id+(2.*D.*dt.*theta).*A;
R_app=Id-2.*D.*dt.*(1-theta).*A;

but it goes Out of Memory.
Could someone help me, please? Thank you in advance!

P.S. I put the double * just in this question, not in the real code.

The right solution is to quote your code: PSA: how to quote code with backticks

I’ve edited your post to fix this. Welcome to the Julia Discourse forum!

Also, it would be easier to help you if you posted a minimal example that is runnable (as opposed to using lots of undefined symbols like Kx and Ay): Please read: make it easier to help you