Error on calling method with "out" parameters.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I don't understand why the following simple code produce an
OutOfMemoryException only on the device and not on the emulator:

private void button1_Click(object sender, System.EventArgs e)
{
double dValue;
double dX,dY,dSum,dSub;

dX=10;
dY=5;

Sum(dX,dY,out dSum, out dSub);
}

public void Sum(double dX, double dY, out double dSum, out double dSub)
{
dSum=dX+dY;
dSub=dX-dY;
}

Do you see an error ?

Thank you in advance for any help.

Keven Corazza
 
Keven that's a good one (or I am tired and missing the obvious :-).

What device are you trying this on and more importantly what CF version are
you running?

I tried your code on our own WinCE 4.2 device running SP2 and got the
OutOfMemoryException as you described.

I tried the same code on a SmartPhone (from the menu click instead of
button) running SP1 and also got the same undesirable result.

The code works in the emulator running RTM (different JIT compiler so that
could be the culprit) and it also works on the desktop (so it doesn't look
like a general .NET issue).

I don't have an SP3 device or a PPC to test this on so can you please make
sure you are running Service Pack 3. If the problem persists with that we'll
see if someone smarter than me can provide an explanation.

In the mean time I have a workaround for you. Please let me know if it works
for you. Replace your Sum function with this one (identical in
functionality):
public void Sum(double dX, double dY, out double dSum, out double dSub)
{
try{
dSum=dX+dY;
dSub=dX-dY;
}catch{
throw;
}
}


Cheers
Daniel
 
Hi Daniel, thank you for your answer.

I'm working with an ASUS device and I've installed yesterday CF SP3. With
SP2 of course I get the same problem.

Your code works but also this code works:

{
dSum=0;
dSub=0;
dSum=dX+dY;
dSub=dX-dY;
}

If I "initialize" the variables it works, if I use directly the variables
dX, dY I get the error. Another test that I do is the following: with only
one "out" parameter it works!

Try to change out in ref: you will get the same error!

I think that what happens is quite grave: I've a lot of functions, like
everyone I suppose, that return values. They seems to work but why they works
and other don't works ?

Hoping in a solution...

Keven Corazza
 
Back
Top