# HP Forums

Full Version: Memory corruption issues with a certain integral.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good evening.
I have created a tiny program to faster integrate over spherical, cylindrical etc. coordinate systems. The relevant part for this example is as follows:
Code:
``` #cas // Vol.elem. vektoriell Sph. Koordinaten function e_sp_vol(p_r,p_ϑ,p_φ) local ret:= ABS(dot(cross(∂(v_r_sp(r,ϑ,φ),r),∂(v_r_sp(r,ϑ,φ),ϑ)),∂(v_r_sp(r,ϑ,φ),φ))); ret:=subst(ret,r=p_r); ret:=subst(ret,ϑ=p_ϑ); ret:=subst(ret,φ=p_φ); return ret; END; // Volumenintegral für ein Skalarfeld in Sph. Koordinaten function int_sp(field,p_r,p_ra,p_rb,p_ϑ,p_ϑa,p_ϑb,p_φ,p_φa,p_φb) local i_field; local ret; i_field := subst(field,p_r=ivar_r); i_field := subst(i_field,p_ϑ=ivar_ϑ); i_field := subst(i_field,p_φ=ivar_φ); ret := ∫(∫(∫(i_field*e_sp_vol(ivar_r,ivar_ϑ,ivar_φ),ivar_φ,p_φa,p_φb),ivar_ϑ,p_ϑa,​p_ϑb),ivar_r,p_ra,p_rb); ret:=subst(ret,ivar_r=p_r); ret:=subst(ret,ivar_ϑ=p_ϑ); ret:=subst(ret,ivar_φ=p_φ); return ret; END; #end```

Basically this program takes the arguments and calculates the attached integral.

The problem is, when this function is executed for a couple of times, the CAS starts to misbehave and memory corruption seems to occur; sometimes the operating system simply crashes. The variable browser in HP Connectivity Kit shows seemingly empty variables with strange contents (see attached screen).

You may test this program by calling it with
Code:
``` int_sp(1,a,0,r,b,0,π,c,0,2*π)```
It sould return the volume of a sphere as it does as long as the memory corruption is not severe enough.

When we restart the CAS, the purged variables look as attached in the screenshot.

Tell me if you have any ideas on what I am missing there.
Kind regards.

Information on the environment:
Prime G2
20210505 update (it was buggy before this version as well)
I think the only way to avoid strange behavior is to delete the "corrupted" variables from CAS memory (Shift + Memory -> Cas Vars, Delete) every time the integral is calculated.
The same thing happens to me too, when I calculate a "difficult" integral: I think that the HP PRIME calculator stores in Cas some "dummy" variables that lead to the resolution of the integral.
Unlikely to be due to lack of memory as its a G2, unless it's a leak or some other memory management issue?