创建大Sitecore的项目数量会导致内存泄漏 [英] Creating big amount of Sitecore Items causes memory leak

查看:154
本文介绍了创建大Sitecore的项目数量会导致内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Sitecore的应用程序,我需要从其他系统的循环创造了大量的Sitecore的项目。下面是我的测试目的循环;

I have a Sitecore application where I need to create a large number of Sitecore items in a loop from another system. Below is my testing purpose loop;

using (new Sitecore.SecurityModel.SecurityDisabler())
{
    for (int i = 0; i < 20000; i++)
    {
        Item newItem = MyTemplateItem.CreateItemFrom(DateTime.Now.Ticks.ToString(), myParentItem);

        newItem.Editing.BeginEdit();
        newItem.Fields["Title"].Value = Guid.NewGuid().ToString();
        newItem.Editing.EndEdit();
    }
}

在这个循环运行,并同时寻找在任务管理器的进程内存使用量越来越增加的时间。

When this loop is running and while looking in task manager, the process memory usage is getting increased with the time.

Sitecore的项目类没有实施的IDisposable 接口,所以我不能调用创建项目的终结。

Sitecore Item class has not implemented IDisposable interface, so I cannot call the Finalizer of the created item.

我怎样才能避免这种内存泄漏?

How can I avoid this memory leak?

PS:我使用的是Windows应用程序来执行此操作绕过IIS进程内存泄漏的地方Sitecore的做它的超高速缓存更新和索引的建筑,应该在这个过程结束时完成

PS: I'm using a windows application to perform this operation to bypass the IIS process memory leak where Sitecore does its cache updating and index building which should be done at the end of this process.

推荐答案

您可以暂时的项目创建过程中禁用数据库高速缓存:

You can temporarily disable the database cache during the item creation:

using (new Sitecore.Data.DatabaseCacheDisabler())

您可以使用在创建过程中禁用索引:

You can disable indexing during the creation using:

Sitecore.Configuration.Settings.Indexing.Enabled = false;

尝试添加这两个东西,看看是否有帮助。

Try to add those two things and see if it helps.

更新: 也许这会工作。 EndEdit中后,你的循环里面添加这个():

UPDATE: Maybe this will work. Add this inside your loop after EndEdit():

newItem = null;

if (i % 100 == 0)
{
  GC.Collect();
  GC.WaitForPendingFinalizers();
}

这将迫使垃圾收集器尝试每100个项目已添加的时间收回未使用的内存。

It will force the garbage collector to try reclaim unused memory every time 100 items have been added.

如果这个工程,那么你真的没有给自己打电话的GC,它会自动在某个时候发生,你只是不知道什么时候。

If this works then you don't really have to call the GC yourself, it will happen automatically at some point, you just don't know when.

这篇关于创建大Sitecore的项目数量会导致内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆