For one thing:
during that loop you are creating 100 ListViewItem objects. Now they
do not account for the memory used, but for some.
In general this is a standard .NET runtime problem. The .NET runtime
needs to cleanup memory, and it will after a while, but to fetch 100
contacts, a lot of objects get created in between, and they first grow
you memory pool.
You might invoke .NET memory cleanup on your own, although that is not
recommended by Microsoft.
To my knowledge the code itself does not leak memory, your sample
there is fine. As soon as you assign the new feed, you will be
releasing all the other objects to the MemoryManager and when it's
time comes, it will clean them up.
Also, when you state you use 500+ kb of memory, you are talking about
the memory before you start the program, correct? So you are not
counting that the .NET runtime is not even loaded yet?
Frank Mantek
Google
On Apr 20, 2009, at 12:07 AM, woolxiang wrote:
>
> Hi, The following code is getting all contact entries in my google
> contact server, and show in listview of dialog
> ===========================================================
> ContactsService m_ContactsService = null;
> m_ContactsService = new ContactsService("ContactClient");
> m_ContactsService.setUserCredentials("Username", "Password");
>
> //Get contacts
> ContactsQuery query = new
> ContactsQuery(ContactsQuery.CreateContactsUri
> ("default"));
> ContactsFeed feed = null;
> feed = m_ContactsService.Query(query);
>
> while (null != feed && feed.Entries.Count > 0)
> {
> foreach (ContactEntry entry in feed.Entries)
> {
>
> ListViewItem item = new ListViewItem
> (entry.Title.Text);
>
> listView1.Items.Add(item);
>
> }
>
> if (feed.NextChunk != null)
> {
> query = new ContactsQuery(feed.NextChunk);
> feed = m_ContactsService.Query(query);
> }
> else
> {
> feed = null;
> }
> }
> ===========================================
> I test this code in my smart phone, and I have about 100 contacts
> when I start this program, It would use 564 KB memory
> and during it getting all contacts, it would use 3.92 MB memory
> I think when I use:
> query = new ContactsQuery(feed.NextChunk);
> feed = m_ContactsService.Query(query);
>
> It does not free memory of old ContactsFeed.
> Maybe it would need garbage collection?
> Does anyone could told me how to do by some sample code?
> Thank you.
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Contacts API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-contacts-api?hl=en
-~----------~----~----~----~------~----~------~--~---