Note that there are some explanatory texts on larger screens.

plurals
  1. POOnly loading and unloading data based on what's visible in a VirtualObjectListView, using ObjectListView?
    text
    copied!<p>I'm writing a video manager in C# using <a href="http://objectlistview.sourceforge.net/cs/index.html" rel="nofollow">ObjectListView</a>, where preview images are generated, saved, and an entry is put into a sqlite db. From there, I use a VirtualObjectListView component to display the entries (Including the first image as a preview) in Details mode.</p> <p>The problem I've ran into is that with several hundred+ entries, it starts to eat up ram and I'm seeing <strong>a lot</strong> of files <em>(Lots of duplicates too)</em> open/locked in Process Explorer. So, I've attempted to implement a caching system - where only 30 images are loaded at a time, and ones not needed are unloaded while new ones are loaded.</p> <p>It doesn't work. It ends up loading multiple copies of each file somehow, and it just feels... Hacky. I've spent the past few days looking for an event or something that I can bind a method to, to do this - but I can't, so I've had to use <strong>GetNthObject</strong> in <strong>AbstractVirtualListDataSource</strong>.</p> <p>Anyways, here's my code:</p> <pre><code>public override object GetNthObject(int n) { VideoInfo p = (VideoInfo)this.Objects[n % this.Objects.Count]; p.ID = n; int storeBufferHalf = 5; int storeFrom = (n - storeBufferHalf &lt; 0) ? 0 : n - storeBufferHalf; int storeTo = (n + storeBufferHalf &gt;= Objects.Count()) ? Objects.Count() - 1 : n + storeBufferHalf; foreach (int cacheItem in cacheList.ToList()) { if (cacheItem &gt;= storeFrom &amp;&amp; cacheItem &lt;= storeTo) continue; VideoInfo unloadItem = (VideoInfo)this.Objects[cacheItem]; //Debug.WriteLine(cacheItem + " Preparing to delete cache: " + unloadItem.Name); unloadItem.DestroyPreviewImage(); cacheList.Remove(cacheItem); } //Load up items into cache. for (int i = storeFrom; i &lt; storeTo; i++) { if (!cacheList.Contains(i)) { VideoInfo loadItem = (VideoInfo)this.Objects[i]; if (loadItem.PreviewImage != null) continue; loadItem.SetPreviewImage(); cacheList.Add(i); } } return p; } </code></pre> <p>Some more information: Basically, it <em>kind of</em> works... It <strong>does</strong> load multiple copies of each file, it does end up loading more images than it should after you scroll down a bit (The entire test DB of 60 items, actually), BUT scrolling the list up and down a few times gets it to unload the files (At least according to Process Explorer).</p> <p>After that, it starts loading them all up again, some of them multiple times...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload