首页 \ 问答 \ NSMutableDictionary中的对象突然变为空(Object in NSMutableDictionary suddenly becomes null)

NSMutableDictionary中的对象突然变为空(Object in NSMutableDictionary suddenly becomes null)

更新:

我添加了一个检查字典中的空对象的方法,事实上,他们被发现:

在NSMutableDictionary中为空

有没有人见过类似的东西? 这不能由不正确的内存管理引起。 请注意,左侧的字典对象树实际上是正确的。

结束更新

我在启用ARC的情况下向NSMutableDictionary添加了一些条目。 添加其中一个之后,突然添加的对象变为空。 这里的代码(我扩大它,以确保我没有发疯):

NSMutableDictionary *base = [NSMutableDictionary dictionary];

id o = [GAConstant kTRUE];
id k = [GAClause parse:@"(x 1 1)"];
[base setObject:o forKey:k];
NSLog(@"### Added (%@ -> %@): %@", k, o, base);

o = [GAClause parse:@"(y X)"];
k = [GAClause parse:@"(x 2 X)"];
[base setObject:o forKey:k];
NSLog(@"### Added (%@ -> %@): %@", k, o, base);

o = [GAConstant kTRUE];
k = [GAClause parse:@"(y 3)"];
[base setObject:o forKey:k];
NSLog(@"### Added (%@ -> %@): %@", k, o, base);

o = [GAConstant kTRUE];
k = [GAClause parse:@"(y 6)"];
[base setObject:o forKey:k];
NSLog(@"### Added (%@ -> %@): %@", k, o, base);

这是输出:

2013-03-25 16:10:33.546 Jungle[1978:11303] ### Added (<GAListClause: 0x75b0dc0> -> <GAConstant: 0x75b12b0>): {
    "<GAListClause: 0x75b1b00>" = "<GAConstant: 0x75b12b0>";
}
2013-03-25 16:10:33.548 Jungle[1978:11303] ### Added (<GAListClause: 0x75b2870> -> <GAListClause: 0x75b1aa0>): {
    "<GAListClause: 0x75b2270>" = "<GAListClause: 0x75b1aa0>";
    "<GAListClause: 0x75b1b00>" = "<GAConstant: 0x75b12b0>";
}
2013-03-25 16:10:33.549 Jungle[1978:11303] ### Added (<GAListClause: 0x75b2b90> -> <GAConstant: 0x75b12b0>): {
    "<GAListClause: 0x75b2d80>" = "<GAConstant: 0x75b12b0>";
    "<GAListClause: 0x75b2270>" = "<GAListClause: 0x75b1aa0>";
    "<GAListClause: 0x75b1b00>" = "<GAConstant: 0x75b12b0>";
}
2013-03-25 16:10:33.550 Jungle[1978:11303] ### Added (<GAListClause: 0x75b2f00> -> <GAConstant: 0x75b12b0>): {
    "<GAListClause: 0x75b2d80>" = "<GAConstant: 0x75b12b0>";
    "<GAListClause: 0x75b2270>" = "<GAListClause: 0x75b1aa0>";
    "<GAListClause: 0x75b1b00>" = "<GAConstant: 0x75b12b0>";
    "<GAListClause: 0x75b1d60>" = (null);
}

方法[GAConstant kTRUE]初始化并返回一个静态变量。 [GAClause parse:]每次都会返回一个新的解析对象。

很明显,为什么k变量的地址不符合字典的内容:它会复制它们。 仍然不清楚null是如何潜入其中的。 字典中null的位置会随着每次运行而改变,有时我会得到其中的两个。

看起来内存管理正在发生,但是什么? ARC在此处启用。

以下是与[GAConstant kTRUE]方法相关的代码:

+ (GAConstant *)kTRUE {
    static GAConstant *kTRUE = nil;
    static dispatch_once_t onceToken = 0;

    dispatch_once(&onceToken, ^{
        kTRUE = [[GAConstant alloc] initWithString:@"true"];
    });

    return kTRUE;
}

有时零字在字典中波动:

2013-03-25 17:09:16.426 Jungle[2294:11303] ### Added (<GAListClause: 0x7182ce0> -> <GAConstant: 0x7183430>): {
    "<GAListClause: 0x7183a30>" = "<GAConstant: 0x7183430>";
}
2013-03-25 17:09:16.428 Jungle[2294:11303] ### Added (<GAListClause: 0x75467b0> -> <GAListClause: 0x71839d0>): {
    "<GAListClause: 0x7546a30>" = (null);
    "<GAListClause: 0x7183a30>" = "<GAConstant: 0x7183430>";
}
2013-03-25 17:09:16.429 Jungle[2294:11303] ### Added (<GAListClause: 0x7546cd0> -> <GAConstant: 0x7183430>): {
    "<GAListClause: 0x7546ec0>" = "<GAConstant: 0x7183430>";
    "<GAListClause: 0x7546a30>" = "<GAListClause: 0x71839d0>";
    "<GAListClause: 0x7183a30>" = "<GAConstant: 0x7183430>";
}
2013-03-25 17:09:16.430 Jungle[2294:11303] ### Added (<GAListClause: 0x7547040> -> <GAConstant: 0x7183430>): {
    "<GAListClause: 0x75470f0>" = (null);
    "<GAListClause: 0x7546ec0>" = "<GAConstant: 0x7183430>";
    "<GAListClause: 0x7546a30>" = "<GAListClause: 0x71839d0>";
    "<GAListClause: 0x7183a30>" = "<GAConstant: 0x7183430>";
}

以下是它在调试器中的样子:

调试器


Update:

I have added a method that checks for null objects in dictionary and indeed, they were found:

Nulls in the NSMutableDictionary

Did anyone ever seen anything like this? This can't be caused by incorrect memory management. Note that dictionary object tree on the left is actually correct.

End update

I'm adding a number of entries to the NSMutableDictionary with ARC enabled. After one of the additions the object added suddenly becomes null. Here's the code (I expanded it to make sure I haven't gone mad):

NSMutableDictionary *base = [NSMutableDictionary dictionary];

id o = [GAConstant kTRUE];
id k = [GAClause parse:@"(x 1 1)"];
[base setObject:o forKey:k];
NSLog(@"### Added (%@ -> %@): %@", k, o, base);

o = [GAClause parse:@"(y X)"];
k = [GAClause parse:@"(x 2 X)"];
[base setObject:o forKey:k];
NSLog(@"### Added (%@ -> %@): %@", k, o, base);

o = [GAConstant kTRUE];
k = [GAClause parse:@"(y 3)"];
[base setObject:o forKey:k];
NSLog(@"### Added (%@ -> %@): %@", k, o, base);

o = [GAConstant kTRUE];
k = [GAClause parse:@"(y 6)"];
[base setObject:o forKey:k];
NSLog(@"### Added (%@ -> %@): %@", k, o, base);

Here's the output:

2013-03-25 16:10:33.546 Jungle[1978:11303] ### Added (<GAListClause: 0x75b0dc0> -> <GAConstant: 0x75b12b0>): {
    "<GAListClause: 0x75b1b00>" = "<GAConstant: 0x75b12b0>";
}
2013-03-25 16:10:33.548 Jungle[1978:11303] ### Added (<GAListClause: 0x75b2870> -> <GAListClause: 0x75b1aa0>): {
    "<GAListClause: 0x75b2270>" = "<GAListClause: 0x75b1aa0>";
    "<GAListClause: 0x75b1b00>" = "<GAConstant: 0x75b12b0>";
}
2013-03-25 16:10:33.549 Jungle[1978:11303] ### Added (<GAListClause: 0x75b2b90> -> <GAConstant: 0x75b12b0>): {
    "<GAListClause: 0x75b2d80>" = "<GAConstant: 0x75b12b0>";
    "<GAListClause: 0x75b2270>" = "<GAListClause: 0x75b1aa0>";
    "<GAListClause: 0x75b1b00>" = "<GAConstant: 0x75b12b0>";
}
2013-03-25 16:10:33.550 Jungle[1978:11303] ### Added (<GAListClause: 0x75b2f00> -> <GAConstant: 0x75b12b0>): {
    "<GAListClause: 0x75b2d80>" = "<GAConstant: 0x75b12b0>";
    "<GAListClause: 0x75b2270>" = "<GAListClause: 0x75b1aa0>";
    "<GAListClause: 0x75b1b00>" = "<GAConstant: 0x75b12b0>";
    "<GAListClause: 0x75b1d60>" = (null);
}

The method [GAConstant kTRUE] initializes and returns a static variable. [GAClause parse:] returns a new parsed object every time.

It's clear why addresses of k variables do not correspond to the contents of the dictionary: it copies them. Still not clear how a null can sneak in as a value. The location of null in the dictionary changes with every run, sometimes I'm getting two of them.

Looks like something is going on with the memory management, but what? ARC is enabled here.

Here's the code relevant to [GAConstant kTRUE] method:

+ (GAConstant *)kTRUE {
    static GAConstant *kTRUE = nil;
    static dispatch_once_t onceToken = 0;

    dispatch_once(&onceToken, ^{
        kTRUE = [[GAConstant alloc] initWithString:@"true"];
    });

    return kTRUE;
}

Sometimes null is fluctuating across the dictionary:

2013-03-25 17:09:16.426 Jungle[2294:11303] ### Added (<GAListClause: 0x7182ce0> -> <GAConstant: 0x7183430>): {
    "<GAListClause: 0x7183a30>" = "<GAConstant: 0x7183430>";
}
2013-03-25 17:09:16.428 Jungle[2294:11303] ### Added (<GAListClause: 0x75467b0> -> <GAListClause: 0x71839d0>): {
    "<GAListClause: 0x7546a30>" = (null);
    "<GAListClause: 0x7183a30>" = "<GAConstant: 0x7183430>";
}
2013-03-25 17:09:16.429 Jungle[2294:11303] ### Added (<GAListClause: 0x7546cd0> -> <GAConstant: 0x7183430>): {
    "<GAListClause: 0x7546ec0>" = "<GAConstant: 0x7183430>";
    "<GAListClause: 0x7546a30>" = "<GAListClause: 0x71839d0>";
    "<GAListClause: 0x7183a30>" = "<GAConstant: 0x7183430>";
}
2013-03-25 17:09:16.430 Jungle[2294:11303] ### Added (<GAListClause: 0x7547040> -> <GAConstant: 0x7183430>): {
    "<GAListClause: 0x75470f0>" = (null);
    "<GAListClause: 0x7546ec0>" = "<GAConstant: 0x7183430>";
    "<GAListClause: 0x7546a30>" = "<GAListClause: 0x71839d0>";
    "<GAListClause: 0x7183a30>" = "<GAConstant: 0x7183430>";
}

Here's what it looks like in the debugger:

Debugger


原文:https://stackoverflow.com/questions/15620084
更新时间:2022-06-13 08:06

最满意答案

问题的答案是doynax发送的回复

"I believe there is a shim in recent versions of Windows limiting the available DPMI memory to 32 MB, for yet more ancient software incapable of unprepared such wast quantities of RAM. You may try creating a DpmiLimit key under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\WOW in the registry to adjust this with the limit in bytes as a DWORD"


The answer to the question is the reply sent by doynax:

"I believe there is a shim in recent versions of Windows limiting the available DPMI memory to 32 MB, for yet more ancient software incapable of unprepared such wast quantities of RAM. You may try creating a DpmiLimit key under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\WOW in the registry to adjust this with the limit in bytes as a DWORD"

相关问答

更多

相关文章

更多

最新问答

更多
  • python的访问器方法有哪些
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。
  • 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
  • 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
  • NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
  • 元素上的盒子阴影行为(box-shadow behaviour on elements)
  • Laravel检查是否存在记录(Laravel Checking If a Record Exists)
  • 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
  • 想学Linux 运维 深圳有哪个培训机构好一点
  • 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
  • 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
  • AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
  • 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
  • 等待EC2实例重启(Wait for an EC2 instance to reboot)
  • 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
  • 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
  • 江民杀毒软件的KSysnon.sys模块是什么东西?
  • 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
  • PerSession与PerCall(PerSession vs. PerCall)
  • C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
  • 平衡一个精灵(Balancing a sprite)
  • n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的