惰性和延​​迟 TreeViewer 问题

发布于 2024-08-12 04:20:45 字数 747 浏览 5 评论 0原文

我实际上有两个问题,但它们有点相关,所以在这里它们作为一个问题...

如何确保使用 TreeViewer(SWT.VIRTUAL< /code>) 和 ILazeTreeContentProvider? 如果一个节点有 5000 个子节点,一旦它们被查看者显示,它们就永远不会被释放, 如果您的树具有大量节点和叶子并且堆大小不够大,因此会出现内存不足错误。 是否有某种最佳实践如何避免由于从未关闭的视图持有包含大量数据(数十万个对象甚至数百万个对象)的树查看器而导致的内存泄漏? 也许有一些回调接口可以让查看器/内容提供者元素具有更大的灵活性?

是否可以将延迟(DeferredTreeContentManager)和延迟(ILazyTreeContentProvider)加载结合起来用于单个TreeViewerSWT.VIRTUAL)? 据我了解,通过查看示例和 API,只能在给定时间使用其中之一,但不能同时使用两者,例如, 仅获取给定节点的可见子节点,并使用 Job API 在单独的线程中获取它们。令我困扰的是 Deferred 方法 加载所有子项。虽然在不同的线程中,你仍然加载所有元素 即使一次只显示最小子集。

如果需要,我可以为我的问题提供代码示例......

我自己目前正在努力解决这些问题,所以如果我同时设法想出一些东西,我会很乐意在这里分享。

谢谢!

问候, 斯维伦

I have actually two questions but they are kind of related so here they go as one...

How to ensure garbage collection of tree nodes that are not currently displayed using TreeViewer(SWT.VIRTUAL) and ILazeTreeContentProvider?
If a node has 5000 children, once they are displayed by the viewer they are never let go,
hence Out of Memory Error if your tree has great number of nodes and leafs and not big enough heap size.
Is there some kind of a best practice how to avoid memory leakages, caused by never closed view holding a treeviewer with great amounts of data (hundreds of thousands objects or even millions)?
Perhaps maybe there is some callback interface which allow greater flexibility with viewer/content provider elements?

Is it possible to combine deffered (DeferredTreeContentManager) AND lazy (ILazyTreeContentProvider) loading for a single TreeViewer(SWT.VIRTUAL)?
As much as I understand by looking at examples and APIs, it is only possible to use either one at a given time but not both in conjunction, e.g. ,
fetch ONLY the visible children for a given node AND fetch them in a separate thread using Job API. What bothers me is that Deferred approach
loads ALL children. Although in a different thread, you It still load all elements
even though only a minimal subset are displayed at once.

I can provide code examples to my questions if required...

I am currently struggling with those myself so If I manage to come up with something in the meantime I will gladly share it here.

Thanks!

Regards,
Svilen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三岁铭 2024-08-19 04:20:45

我发现 Eclipse 框架有时会让人精神分裂。我怀疑与 ILazyTreeContentProvider 相关的 DeferredTreeContentManager 就是其中一种情况。

在另一个示例中,在去年的 EclipseCon 上,他们建议您使用适配器工厂 (IAdapterFactory) 来使您的模型适应当时所需的绑定上下文。例如,如果您希望模型显示在树中,请这样做。

treeViewer = new TreeViewer(parent, SWT.BORDER);
IAdapterFactory adapterFactory = new AdapterFactory();
Platform.getAdapterManager().registerAdapters(adapterFactory, SomePojo.class);
treeViewer.setLabelProvider(new WorkbenchLabelProvider());
treeViewer.setContentProvider(new BaseWorkbenchContentProvider());

注册您的适配器,BaseWorkbenchContentProvider 将在工厂中找到该适配器。精彩的。听起来像是一个计划。

“哦,顺便说一句,当你有大型数据集时,请这样做”,他们说:

TableViewertableViewer = new TableViewer(parent, SWT.VIRTUAL);
// skipping the noise
tableViewer.setItemCount(100000);
tableViewer.setContentProvider(new LazyContentProvider());
tableViewer.setLabelProvider(new TableLabelProvider());
tableViewer.setUseHashlookup(true);
tableViewer.setInput(null);

事实证明,第一个和第二个例子不仅不兼容,而且是相互排斥的。这两种方法可能由没有共同计划的不同团队实施,或者 API 可能正处于向通用框架过渡的过程中。尽管如此,你还是得靠自己。

I find the Eclipse framework sometimes schizophrenic. I suspect that the DeferredTreeContentManager as it relates to the ILazyTreeContentProvider is one of these cases.

In another example, at EclipseCon this past year they recommended that you use adapter factories (IAdapterFactory) to adapt your models to the binding context needed at the time. For example, if you want your model to show up in a tree, do it this way.

treeViewer = new TreeViewer(parent, SWT.BORDER);
IAdapterFactory adapterFactory = new AdapterFactory();
Platform.getAdapterManager().registerAdapters(adapterFactory, SomePojo.class);
treeViewer.setLabelProvider(new WorkbenchLabelProvider());
treeViewer.setContentProvider(new BaseWorkbenchContentProvider());

Register your adapter and the BaseWorkbenchContentProvider will find the adaption in the factory. Wonderful. Sounds like a plan.

"Oh by-the-way, when you have large datasets, please do it this way", they say:

TableViewertableViewer = new TableViewer(parent, SWT.VIRTUAL);
// skipping the noise
tableViewer.setItemCount(100000);
tableViewer.setContentProvider(new LazyContentProvider());
tableViewer.setLabelProvider(new TableLabelProvider());
tableViewer.setUseHashlookup(true);
tableViewer.setInput(null);

It turns out that first and second examples are not only incompatible, but they're mutually exclusive. These two approaches where probably implemented by different teams that didn't have a common plan or maybe the API is in the middle of a transition to a common framework. Nevertheless you're on your own.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文