marked for unload due to memory pressure

本文讨论了在使用SQL Server 2005和2008的链接服务器特性时可能遇到的内存泄漏问题,特别是与远程存储过程执行及sql_variant数据类型有关的情况,并提供了缓解措施。

If you use the linked server feature with SQL Server 2005 and 2008, please read through this carefully. We have discovered several problems that can result in memory leak(s). The conditions are a bit complicated so let me try to describe the problems, how you could be affected, and what action(s) you can take.

SQL Server 2008

  • ANY remote stored procedure execution will leak memory for each execution on the local server (the server where you initiated the remote procedure execution). The leak is not large for each execution (around 40 bytes) but over time this can add up. This specific problem involves the RETURN status of a stored procedure so there is no way to avoid it (even if you don’t use RETURN in your proc a return status is sent back to the client) if you execute remote stored procedures.
  • If you use sql_variant SQL Server data types you could also face a different memory leak (again on the local server only). These leaks can occur under the following conditions: 
    • If you use a sql_variant type for an OUTPUT parameter of a remote stored procedure you will leak around 40 bytes just for using a sql_variant OUTPUT parameter (the leak is per parameter). If the value of the parameter is of type char, varchar, nchar, nvarchar,binary, or varbinary, you will also leak the size of the value itself for each parameter. So a large character string over time could result in a considerable memory leak.
    • if you run a remote query that returns a result with a sql_variant column AND the value of the column is a char, varchar, nchar, nvarchar, binary, or varbinary value, you will leak the value of that variant for each row returned to the local server. This one has a potential to cause a fairly significant leak depending on how big the values are and how many rows are returned.

SQL Server 2005

  • You are only affected by the sql_variant problems listed above.

This problem occurs if the linked server query uses the the SQL Server Native Client (SNAC) provider (this will happen with both the SNAC9 and SNAC10 providers), or the Microsoft OLE-DB Provider for SQL Server. The problem is specific to how the SQL Server engine handles a SSVARIANT structure so only applies to SQL Server providers. If you add a linked server query through Management Studio and pick “SQL Server” you are using the SQL Server Native Client so you would be subject to this problem.

I’ve tried to plan head of time a FAQ on this topic to help fill in more details:

1) Are these memory leak problems fixed?

The first problem is..…but not completely (yet). The first problem for a leak of return status values is fixed in SQL Server 2008 CU3 for SP1 (Note the specific FIX article for this problem is not published yet). That problem doesn’t happen in SQL Server 2005 so no need for a fix with that version. We are also looking to create a fix for this in the next cumulative update for SQL Server 2008 RTM.

For the sql_variant problem, we are also looking to create fixes for SQL Server 2005 CU6 for SP3 and for SQL Server 2008 RTM and SP1 in a future cumulative update.

Please note that the fix for this problem is within the SQL Server Engine code, not in the SNAC code. Therefore, when you are applying a fix from the CU updates, you need to pick the complete update package. For SQL Server 2008 CU3 for SP1 this package is called SQL_Server_2008_SP1_Cumulative_Update_3. This package also includes any update to SNAC. The package called SQL_Server_2008_SP1_Cumulative_Update_3_SNAC just contains updates to the SNAC providers so don’t try to just pick this package to get a fix for this problem.

2) What can I do to avoid the problem if a fix is not available yet?

Aside from not running remote procedures or using sql_variant columns, there is no way to avoid the problem. For 32bit customers, you may be able to mitigate VAS issues this problem causes by running all linked server queries out of process.

3) What symptoms can I see due to this problem?

It is possible you will never see a problem depending on which condition of the leak(s) you are hitting. For example, for the “return status” leak, the leak is only around 40 bytes for each procedure execution. You may run for weeks or even months without this causing a problem. For 32bit users, this may cause you problems quicker because of the limited amount of VAS space. Running the linked server out of process can definitely help your situation for 32bit. Note the memory that is leaked here is in the default Windows heap for the SQLSERVR.EXE process, not in the Buffer Pool. This is why for a 32bit SQL Server installation the problem might result in memory errors because the VAS is limited (e.g.MemToLeave)

The problem was first reported to us because of a 32bit system that saw errors in the ERRORLOG like:

Date Time SPID AppDomain 1411 (mch.dbo[runtime].1516) is marked for unload due to memory pressure.
Date Time SPID AppDomain 1411 (mch.dbo[runtime].1516) unloaded.

These messages can occur due to memory pressure (typically VAS pressure for 32bit and physical memory pressure for 64bit). But there are other types of memory related errors that might occur due to a leak of heap memory.

As future fixes for this problem are released, I’ll update this blog post at http://blogs.msdn.com/psssql/ 

Bob Ward
Microsoft

 

 

 

http://social.microsoft.com/Forums/zh-CN/sqlserverzhchs/thread/73d752ac-0678-45ca-bf78-d67e60c4327e

<think>好的,我现在要解决UE4中出现的UObject.Class AttemptToFindUninitializedScriptStructMembers错误。用户提供的引用资料里有关于UObject的使用、动态指针存储、蓝图加载等内容。首先,我需要理解这个错误的原因。 根据错误信息,应该是脚本结构体成员未初始化导致的。结构体在UE4中需要特别注意初始化,特别是在涉及到序列化或垃圾回收时。引用[3]提到动态存储UObject指针的问题,可能和结构体未正确初始化有关。引用[4]指出UObject的序列化功能,如果结构体成员未初始化,可能在序列化过程中引发错误。 接下来,检查代码中是否有自定义的USTRUCT结构体,这些结构体的成员变量是否都正确初始化。比如,是否有指针未初始化或者基本类型变量没有赋予默认值。根据引用[5],可能需要使用UPROPERTY宏来确保变量被正确管理,避免被垃圾回收错误处理。 另外,引用[1]和[2]提到UObject实例化和蓝图加载,如果在结构体中引用了UObject或蓝图类,需要确保这些引用正确初始化,并在UPROPERTY中适当标记,比如使用VisibleAnywhere或EditDefaultsOnly,以帮助引擎正确管理。 可能的解决方案包括:检查所有USTRUCT的定义,确保成员变量都有适当的默认值;在构造函数中进行显式初始化;确保所有UObject指针都有UPROPERTY宏声明,防止被错误回收。此外,清理项目并重新生成工程文件,有时编译缓存问题也会导致此类错误。 需要一步步排查,首先从结构体定义开始,然后检查初始化代码,最后确保所有依赖项正确加载。如果问题仍然存在,可能需要查阅UE4文档或论坛,寻找类似问题的解决方案。</think>### 解决方案:修复`UObject.Class AttemptToFindUninitializedScriptStructMembers`错误 此错误通常与**未初始化的USTRUCT成员变量**或**脚本结构体序列化问题**相关。以下是具体修复步骤: --- #### 1. **检查自定义USTRUCT的定义** 确保所有USTRUCT中的成员变量**显式初始化**,避免使用未定义的默认值。 **错误示例**: ```cpp USTRUCT() struct FMyStruct { int32 UninitializedValue; // 未初始化,可能引发错误 }; ``` **修复方法**: ```cpp USTRUCT() struct FMyStruct { GENERATED_BODY() // 必须包含此宏 int32 InitializedValue = 0; // 显式赋默认值 UPROPERTY() UMyObject* MyObjectPtr = nullptr; // UObject指针必须初始化为nullptr }; ``` --- #### 2. **确保USTRUCT构造函数初始化** 如果USTRUCT需要复杂初始化,**显式定义构造函数**并初始化成员变量。 ```cpp USTRUCT() struct FMyStruct { GENERATED_BODY() FMyStruct() : Value(0), ObjectPtr(nullptr) {} // 构造函数显式初始化 int32 Value; UPROPERTY() UMyObject* ObjectPtr; }; ``` --- #### 3. **验证UPROPERTY宏的使用** 所有引用UObject或派生类的指针必须标记`UPROPERTY()`,否则会被垃圾回收系统误处理[^4]。 **错误示例**: ```cpp USTRUCT() struct FMyStruct { UMyObject* UnmarkedPointer; // 未标记UPROPERTY,可能导致错误 }; ``` **修复后**: ```cpp USTRUCT() struct FMyStruct { UPROPERTY() UMyObject* SafePointer; // 标记后引擎会正确管理其生命周期 }; ``` --- #### 4. **检查序列化逻辑** 如果结构体需要序列化(如存档功能),确保所有成员变量支持序列化。非POD类型或复杂类型需额外处理[^3]。 ```cpp void FMyStruct::Serialize(FArchive& Ar) { Ar << InitializedValue; // 序列化基本类型 Ar << SafePointer; // 序列化UObject指针(需确保指针有效性) } ``` --- #### 5. **清理编译缓存** 若问题持续,删除以下目录并重新编译: - `项目目录/Binaries` - `项目目录/Intermediate` 此操作可消除因缓存导致的编译错误[^1]。 --- #### 6. **验证蓝图引用** 如果结构体中包含蓝图资源路径(如引用`AActor`类),确保路径正确且资源已加载[^2]: ```cpp // 示例:加载蓝图类 FString ClassPath = "/Game/Path/To/Blueprint.Blueprint_C"; UClass* ActorClass = LoadClass<AActor>(nullptr, *ClassPath); ``` --- ### 相关问题 1. **如何避免UE4中UObject指针的无效引用?** 需始终使用`UPROPERTY()`标记指针,并遵循[UE4的垃圾回收规则](https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Objects/Optimizations/#garbagecollection)。 2. **UE4结构体序列化失败可能的原因?** 未实现`Serialize`函数、成员变量类型不支持序列化,或未正确初始化。 3. **如何调试UE4中的蓝图加载错误?** 使用`UE_LOG`输出资源路径,或通过`GetClass()/GetName()`验证加载结果[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值