Board index » delphi » Freeing a list view with > 10.000 items

Freeing a list view with > 10.000 items

My application fills a list view with over 10.000 items. So far no problems.
But when I close my application, it takes a while before all the items have
been freed. All forms are closed, but the application is still visible in
the taskbar for a few seconds, and that looks a bit silly.

Any suggestions on how to close the application gracefully?

- daniel

 

Re:Freeing a list view with > 10.000 items


Quote
> My application fills a list view with over 10.000 items. So far no
problems.
> But when I close my application, it takes a while before all the items
have
> been freed. All forms are closed, but the application is still visible in
> the taskbar for a few seconds, and that looks a bit silly.

> Any suggestions on how to close the application gracefully?

You could always hide the taskbar button in your OnClose event on the main
form. This way, although your app is still freeing resources, it will give
the appearance of being terminated.

To hide the taskbar button use,

ShowWindow(Application.Handle, SW_HIDE);

HTH,

Adam.

Re:Freeing a list view with > 10.000 items


Quote
> You could always hide the taskbar button in your OnClose event on the main
> form. This way, although your app is still freeing resources, it will give
> the appearance of being terminated.

Yep, that would be a nice thing to do... thanks Adam!

- daniel

Re:Freeing a list view with > 10.000 items


In article <1006034105.941...@cereal.attica.net.nz>, "Daniel Rutten"

Quote
<n...@junk.com> wrote:

[......]

Daniel, please email me.

-- Esther

Re:Freeing a list view with > 10.000 items


What happens if you clear the listview yourself with:

ListView1.Items.BeginUpdate;
try
  ListView1.Items.Clear;
finally
  ListView1.Items.EndUpdate;
end;

Quote
"Daniel Rutten" <n...@junk.com> wrote in message

news:1006034105.941079@cereal.attica.net.nz...
Quote
> My application fills a list view with over 10.000 items. So far no
problems.
> But when I close my application, it takes a while before all the items
have
> been freed. All forms are closed, but the application is still visible in
> the taskbar for a few seconds, and that looks a bit silly.

> Any suggestions on how to close the application gracefully?

> - daniel

Re:Freeing a list view with > 10.000 items


Quote
> What happens if you clear the listview yourself with:

Good suggestion, but it's the Clear itself that is causing the delay and
using the BeginUpdate and EndUpdate does not reduce the time needed
significantly (see below).

The thing that is really worrying me is that it is not a linear, but an
exponential process for both the creation and destruction of items:

With BeginUpdate and EndUpdate:

Items   Add*   Clear*
1000   2.15   0.33
2000   5.12   0.94
3000   10.60   1.70
4000   17.52   2.86
5000   28.01   4.67
6000   39.11   5.98
7000   51.30   8.19
8000   65.80   10.93
9000   82.66   12.96
10000   101.95   15.87

Without BeginUpdate and EndUpdate:

Items  Add*   Clear*
1000   2.20   0.66
2000   5.99   1.59
3000   11.97   3.02
4000   18.84   4.40
5000   31.42   6.26
6000   42.95   8.18
7000   55.81   10.87
8000   69.59   13.40
9000   84.20   15.71
10000   102.88   19.22

* in seconds

The creation of the items is not really a problem, because I can create them
in a seperate thread to avoid a 'lock-up' of the program. Freeing _is_ a
problem, because of the huge delay. After closing the program it can take up
to a minute to free all created objects (my program uses five listviews with
each around 10.000 items), and AFAIK there isn't a 'nice' way around it.

Unless any of you has a really good solution for this...

- daniel

Re:Freeing a list view with > 10.000 items


It seems to me that _any_ system which has "10,000 items in a list box,"
let alone several of them, ought to be looking seriously at ways to
simplify that design.  How could anyone troll through, or find anything
in, a list-box like that?

If the goal is to allow (e.g.) auto-completing of user inputs, then
there are many ways to handle that chore with a custom or off-the-shelf
control .. without actually handling ten-thousand items.

Quote
Daniel Rutten wrote:

> > What happens if you clear the listview yourself with:

> Good suggestion, but it's the Clear itself that is causing the delay and
> using the BeginUpdate and EndUpdate does not reduce the time needed
> significantly (see below).

> The thing that is really worrying me is that it is not a linear, but an
> exponential process for both the creation and destruction of items:

> With BeginUpdate and EndUpdate:

> Items   Add*   Clear*
> 1000   2.15   0.33
> 2000   5.12   0.94
> 3000   10.60   1.70
> 4000   17.52   2.86
> 5000   28.01   4.67
> 6000   39.11   5.98
> 7000   51.30   8.19
> 8000   65.80   10.93
> 9000   82.66   12.96
> 10000   101.95   15.87

> Without BeginUpdate and EndUpdate:

> Items  Add*   Clear*
> 1000   2.20   0.66
> 2000   5.99   1.59
> 3000   11.97   3.02
> 4000   18.84   4.40
> 5000   31.42   6.26
> 6000   42.95   8.18
> 7000   55.81   10.87
> 8000   69.59   13.40
> 9000   84.20   15.71
> 10000   102.88   19.22

> * in seconds

> The creation of the items is not really a problem, because I can create them
> in a seperate thread to avoid a 'lock-up' of the program. Freeing _is_ a
> problem, because of the huge delay. After closing the program it can take up
> to a minute to free all created objects (my program uses five listviews with
> each around 10.000 items), and AFAIK there isn't a 'nice' way around it.

> Unless any of you has a really good solution for this...

----------------------------------------------------------------
Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
mailto:i...@sundialservices.com  (PGP public key available.)

- Show quoted text -

Quote
> Fast(!), automatic table-repair with two clicks of the mouse!
> ChimneySweep(R):  Release 4.0 is here!!
> http://www.sundialservices.com/products/chimneysweep

Re:Freeing a list view with > 10.000 items


Quote
"Daniel Rutten" <daniel.rutte...@SPAMclickwise.co.nz> wrote in message
> The creation of the items is not really a problem, because I can create
them
> in a seperate thread to avoid a 'lock-up' of the program. Freeing _is_ a
> problem, because of the huge delay. After closing the program it can take
up
> to a minute to free all created objects (my program uses five listviews
with
> each around 10.000 items), and AFAIK there isn't a 'nice' way around it.

> Unless any of you has a really good solution for this...

The program is dealing with 50K items. ISTM that you really should be
looking at using a good db based listview. Keeping it all in memory seems
pointless to me since few users would be able to work with that much data at
one time. A good db shouldn't impact negatively on performance and will
certainly resolve the shutdown situation.

Re:Freeing a list view with > 10.000 items


Yeah, what usually happens is that, say, the user enters a few numbers
.. then maybe presses a button on the control (or maybe just tabs out of
it, having entered a complete and valid key), and THEN, (bang!!) that
control fires off a query to fetch the matching item[s].

If the user's request is not specific enough to keep the list of items
reasonable, say less than 100, then it's common to see the request
rejected:  "please be more specific."

Quote
>Bruce Roberts wrote:

> "Daniel Rutten" <daniel.rutte...@SPAMclickwise.co.nz> wrote in message

> > The creation of the items is not really a problem, because I can create
> them
> > in a seperate thread to avoid a 'lock-up' of the program. Freeing _is_ a
> > problem, because of the huge delay. After closing the program it can take
> up
> > to a minute to free all created objects (my program uses five listviews
> with
> > each around 10.000 items), and AFAIK there isn't a 'nice' way around it.

> > Unless any of you has a really good solution for this...

> The program is dealing with 50K items. ISTM that you really should be
> looking at using a good db based listview. Keeping it all in memory seems
> pointless to me since few users would be able to work with that much data at
> one time. A good db shouldn't impact negatively on performance and will
> certainly resolve the shutdown situation.

Re:Freeing a list view with > 10.000 items


Quote
> It seems to me that _any_ system which has "10,000 items in a list box,"
> let alone several of them, ought to be looking seriously at ways to
> simplify that design.

I agree with you that this system is a wee bit exraordinary.

Quote
> How could anyone troll through, or find anything
> in, a list-box like that?

By using filters... however, if a user does not apply a filter, he'll end up
with approx 10.000 items. It is not wise, but it is possible and in this
case, clearing the list will take up a lot of time.

I have redesigned the thing, so that using a filter is compulsory, but the
original question remains...

- daniel

Re:Freeing a list view with > 10.000 items


When I have to manage more than 1000 items in a ListView, I use a virtual
one.

I manage items myself, it takes some developement time, but performance has
this cost.

See online help for more info on virtual list views.

"Daniel Rutten" <n...@junk.com> a crit dans le message de news:
1006034105.941...@cereal.attica.net.nz...

Quote
> My application fills a list view with over 10.000 items. So far no
problems.
> But when I close my application, it takes a while before all the items
have
> been freed. All forms are closed, but the application is still visible in
> the taskbar for a few seconds, and that looks a bit silly.

> Any suggestions on how to close the application gracefully?

> - daniel

Re:Freeing a list view with > 10.000 items


Im Artikel <1006118103.116...@cereal.attica.net.nz>, "Daniel Rutten"
<daniel.rutte...@SPAMclickwise.co.nz> schreibt:

Quote
>The thing that is really worrying me is that it is not a linear, but an
>exponential process for both the creation and destruction of items:

Don't worry, I had much more annoying problems with a Tree/ListView control
some years ago. Can you imagine a control which requires 5 seconds to fill, and
15 minutes to Clear? Yes, that's what Windows is designed for :-(

Most time does Clear spend in memory deallocation, together with the resolution
of crosslinked items. Unfortunately the user has no reasonable means to speed
up that process - either you accept that deficiency, or you better use a
different component, which is free of any OLE stuff.

DoDi

Re:Freeing a list view with > 10.000 items


Quote
> When I have to manage more than 1000 items in a ListView, I use a virtual
> one.

> I manage items myself, it takes some developement time, but performance
has
> this cost.

Could you give me an example of how to do this?

- daniel

Re:Freeing a list view with > 10.000 items


Quote
"Daniel Rutten" <daniel.rutte...@SPAMclickwise.co.nz> wrote in message
> By using filters... however, if a user does not apply a filter, he'll end
up
> with approx 10.000 items. It is not wise, but it is possible and in this
> case, clearing the list will take up a lot of time.

> I have redesigned the thing, so that using a filter is compulsory, but the
> original question remains...

Use a db. tTable has a Filter property which will save you a lot of code, or
use tQuery to filter the data - its even more powerful.

Re:Freeing a list view with > 10.000 items


Quote
"Daniel Rutten" <daniel.rutte...@SPAMclickwise.co.nz> wrote in message

news:1006203259.922444@cereal.attica.net.nz...

Quote
> > When I have to manage more than 1000 items in a ListView, I use a
virtual
> > one.

> > I manage items myself, it takes some developement time, but performance
> has
> > this cost.

> Could you give me an example of how to do this?

set listview.ownerdata
then write the OnData method
(others like ondatahint to preload items as well but ondata is all you need)
this gives you an item to fill in, the index tells you what element it is

Say you intend to display two columns of text
you decide to preallocate them and manipulate the data at Tstringlist
you want to see what proceesing would be involved for  300,000 entries
(just to illustrate not meant to be best way ;-)

 sl1:=tstringlist.create;
 sl2:=tstringlist.create;
 listview1.count:=300000;  //set listview to have 300k virtual entries

 for i:=0 to listview1.items.count-1 do
   begin
        sl1.Add('column1 '+inttostr(i));
        sl2.Add('column2 '+inttostr(i));
   end;

the ondata just has to fill in each line when the listview needs it

procedure TForm1.ListView1Data(Sender: TObject; Item: TListItem);
begin
  if sl1 <> nil then
    if item.index <= sl1.count then
    Item.caption:=sl1.Strings[item.index]
   else
       item.caption:='unfound col 1 , entry '+inttostr(item.index);
if sl2 <> nil then
    if item.index <= sl2.count then
    item.subitems.Add(sl2.strings[item.index])
    else
        item.subitems.Add('unfound col 2 , entry'+inttostr(item.index));
end;

to free the data for 300k 'items' is probably a few billion times
faster then for a 300k non-virtual listview

 sl1.free; sl1:=nil;
 sl2.free; sl2:=nil;
 listview1.count:=0;
 listview1.Refresh;

Go to page: [1] [2]

Other Threads