Performance worrying problem - Bad architecture maybe

  • Thread starter Thread starter Lonifasiko
  • Start date Start date
L

Lonifasiko

Hi guys,

I've got a very worrying problem in my CF 2.0 application. I don't know
the exact reason for so poor performance, sometimes combined with
"OutOfMemoryException" messages. Could be a bad architecture design
problem.

Ths is my actual scenario:

The application has got near 25 forms and I have one MasterForm from
which the rest of the forms inherit. This MasterForm contains basically
icons and some static variables I use for different purposes inside all
forms of my application.

I call the first form of my application "MainForm". Here we have three
very different choices (imagine three buttons).
When any button is clicked, I always open corresponding form with
ShowDialog() method. Each choice can simultaneously open 5/6 forms
maximum by using ShowDialog(). Therefore, I understand 5/6 forms are
opened in memory sametime. Correct me if I'm wrong please.

Imagine that I choose a button and navigate and navigate and.....I
finally have 5/6 forms opened with ShowDialog(). When I close the
actual modal form (fifth or sixth form), I use the simple this.Close()
and sometimes also return a DialogResult value. If the previous form
must perform an specific action, I use static variables of the previous
form, which I activate from the actual modal form.

In the previous form, I capture Activate event and do the correct
action if the corresponding static variable has been activated. An
example would be to save something and when returning to the previous
form, refreshing the screen with the newly saved data. This means a new
database access. This could be the main bottleneck of the application.

The operations are against SQL Mobile 2005 database. I always access
database to retrieve
latest data, don't use caching at all.

With this scenario, all I can tell you is that sometimes application
seems not to response, and ultimately, if you stress it hard,
"OutOfMemoryException" occurs and new data is not refreshed in the
screen. Suddenly data is "lost", and if you close the from and open it
again, data appears again......in one word: desperating!

I would like to hear any suggestion for a better performance please. It
really hurries me. My project is becoming more and more complex and I
think now, I've got the last chance to reorient or redesign its
architecture. 2006 could be too late.

Specially advices related to the way of opening/closing forms and
database accessing and caching.

Thanks very much. Regards.
 
Forms shown with ShowDialog are intentionally not disposed when closed, as
the runtime assumes it will be used again. If you're doing something like
this, you're going to have a problem:

OnButtonClick(...)
{
MyForm frm = new MyForm();
frm.ShowDialog();
}

This will create a new form instance every time the routine runs, and since
they're never explicitly destroyed, you could have garbage all over the
place. Especially if you're running an early CF 1.0 release, which had a
bug that didn't dispose all Form internals.

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 
Hi Chris,

I'm using new CF 2.0, but as you say, I'm running the snippet of code
you mention everytime a user clicks on the corresponding button or
whatever executing that routine.

Then, as far as I understand: I open from my first form a modal form
with ShowDialog(), I do whatever in that form (save a contact in
database for example) and then I close that form with this.Close(),
sometimes returning a DialogResult. You mean that although I have
closed the modal form, it is still running when I'm back in first form?
Now, back in the first form, user clicks again the button. Another
instance of the modal form is created? Or the running instance is
somehow reused? I would have two instances of the same form running?
That could be the reason for such a bad performance?

What do you suggest me then?

I will appreciate any help on this. Regards.
 
Lonifasiko said:
I'm using new CF 2.0, but as you say, I'm running the snippet of code
you mention everytime a user clicks on the corresponding button or
whatever executing that routine.
...
What do you suggest me then?

Try this:

OnButtonClick(...)
{
MyForm frm = new MyForm();
frm.ShowDialog();

// Do something with result.

// Dispose of the form.
frm.Dispose();
}


--
John T
http://tknowlogy.com/TknoFlyer
http://www.pocketgear.com/products_search.asp?developerid=4415
Reduce spam. Use Sender Policy Framework: http://spf.pobox.com
____________________
 
Or alternatively:

private m_frm = new MyForm();

OnButtonClick(...)
{
frm.ShowDialog();

// Do something with result.
}

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 
Hi,

I'll try both the solutions.

This way I can be sure the modal form is going to be disposed and
correctly garbaged? Would be nice if my performance problems dissapear.


I suppose combining Show() and Hide() methods will also be very
expensive and unthinkable when talking about performance. Hide()
mantains all the structure of the form loaded in memory, doesn't it?

What about using threads? I tried some weeks ago, but I had problems
because when a new thread was started, from this new execution
environment I didn't have access to global variables from the
MasterForm, which runs in a the main thread of the application. What do
you think about this option?

I'll try both solutions and if I have more questions or does not
improve performance at all, I'll come back here again. I hope
performance will be significantly improved with your two little tricks.


Thanks very much for the info.
 
Hi again,

I've also noticed that the two PDAs having memory problems curiously
have 64 Mbytes of RAM whereas the other PDA have 128 Mbytes. We
haven´t stressed this last PDA yet, but 64MBytes maybe are not enough?


What do you think about?
 
Lonifasiko said:
I've also noticed that the two PDAs having memory problems curiously
have 64 Mbytes of RAM whereas the other PDA have 128 Mbytes. We
haven´t stressed this last PDA yet, but 64MBytes maybe are not enough?

It depends on the amount of data you're storing on the device and how much
of that you're pulling into memory during execution of your app. Large data
files consume memory and if you're not careful how you read the file and use
the data, you could duplicate that data in application memory. This was one
of the concerns behind creation of the new SqlCeResultSet.

One of the "good things" about mobile device development is it forces
developers to once again pay attention to the resources they use in their
apps. :)

--
John T
http://tknowlogy.com/TknoFlyer
http://www.pocketgear.com/products_search.asp?developerid=4415
Reduce spam. Use Sender Policy Framework: http://spf.pobox.com
____________________
 
Note that your app/process can only use up to a maximum of 32MB in all
cases. So it depends on what else is running on your target.

For more on that, read point 5 here:
http://www.danielmoth.com/Blog/2005/01/memory-problems-faq.html

Cheers
Daniel
--
http://www.danielmoth.com/Blog/

Hi again,

I've also noticed that the two PDAs having memory problems curiously
have 64 Mbytes of RAM whereas the other PDA have 128 Mbytes. We
haven´t stressed this last PDA yet, but 64MBytes maybe are not enough?


What do you think about?
 
That's not entirely true. Apps can use RAM from shared memory outside the
32MB process slot, and in fact that's where the CLR allocates space for
loading assemblies.

-Chris
 
Back
Top