views:

65

answers:

1

Hi,

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

A: 

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.

Rui Pacheco