随机消失的结构
我创建了一个 Objective-C 类来使用 libpq 与 PostgreSQL 交互。它基本上可以工作,但我有一个小问题 - 连接似乎随机消失。
此类设置为在打开窗口时打开连接,并在窗口关闭之前关闭该连接。在窗口的初始化代码中,我打开连接并监听通知,以便可以使用 PQfinnish() 关闭连接。
现在,如果我打开该窗口,我可以运行任意数量的查询。但如果我关闭它并再次打开它,我会收到 EXC_BAD_ACCESS 错误。该错误似乎在 libpq 内部,但我不知道我做错了什么 - 没有可遵循的示例,这使得遵循模式变得有点困难。
我相信连接对象似乎有问题,但我无法准确找出问题所在,因为所有诊断函数似乎都返回正确的值。
Postgresql 8.0,运行在最新的 OS X、最新的 Xcode 和目标为 10.5 的项目上
I've created a Objective-C class to interface with PostgreSQL using libpq. It mostly works but I have one small problem - the connection seems to disappear randomly.
This class is set to open a connection when a window is opened and close that connection before the window closes. On the init code of the window I open the connection and I listen to notifications so I can close the connection with PQfinnish().
Now if I open that window, I can run as many queries as I want. But if I close it and open it again I get an EXC_BAD_ACCESS error. The error seems to be inside libpq but I've no idea what I'm doing wrong - there's no examples to follow which makes it a bit harder to follow patterns.
I believe there seems to be a problem with the connection object but I can't find out exactly what as all diagnostic functions seem to be returning the right values.
Postgresql 8.0, running on latest OS X, latest Xcode and project targeted at 10.5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到答案:
崩溃的代码是从通知触发的事件中调用的。崩溃是因为我在关闭窗口时没有从通知中心取消注册该类。
我现在从中心取消注册该课程,一切正常。
但不知道为什么问题会反映在连接对象上。
Found the answer:
The code that crashed was called from an event that was fired from a notification. The crash came because I wasn't unregistering that class from the notification centre when closing the window.
I now unregister that class from the centre and all works well.
No idea why the problem reflected itself on the connection object, though.