Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Crashing when working with an array passed via NSNotification

Crashing when working with an array passed via NSNotification
Thread Tools
Mac Enthusiast
Join Date: Apr 2001
Location: Newton, MA, USA
Status: Offline
Reply With Quote
Apr 26, 2004, 04:18 PM
 
I've been banging my head against the wall for a while on this one, and was wondering if anyone might be able to suggest anything that i might've stupidly overlooked (i'm just a hobbyist, and have precious little training in programming).

Basically what's going on is that my document class stores information in two arrays, one being derived from a process upon the other. The idea is to use that information to draw a graph that appears in a second window. The custom view object doesn't exist until that second window is summoned, though, so the information makes kind of a roundabout trip to get there. I'm using Notifications to pass the object from the document to the application controller, which passes it to the graph window controller at the time the view is created. and this works great the first time around; the custom view receives the array and can work with the information therein. But if i close one document and open the other, the custom view code crashes the program as soon as i do something like foo=[incomingArray count] or something.

The behavior's consistent with a situation where i'm accessing something that's been thrown away or something, but i've gone over that a hundred times now, and haven't been able to find it.

Any suggestions on what i might be missing? Is this a completely brain-dead way to pass the information (i've tried an interlocking set of get/set functions that accomplish the same task, too)?

Thanks as always for any advice; should i ever become smart enough to lend a hand, rest assured i will try to return the favor.
(Last edited by calamar1; Apr 27, 2004 at 01:36 PM. )
     
Forum Regular
Join Date: Aug 2001
Location: Vienna, Austria
Status: Offline
Reply With Quote
Apr 29, 2004, 06:11 AM
 
Yes, that object is definitely over-released. Without seeing the source, it's hard to find any cause, but I'd guess that you're releasing something on window close and aren't replacing it. Try setting everything to nil after release, that should help tracking it down (messages to nil are ignored).
     
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Apr 29, 2004, 06:38 PM
 
You're probably passing something that's been autoreleased before you even got it? In which case you shouldn't be releasing it at all yourself.

In any case, why are you using a notification to communicate between your two objects? Can't you call one object's method directly from the other object? (May require making sure both objects are aware of each other when the controller initialises the other object).
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Apr 29, 2004, 08:13 PM
 
Without seeing some of your code, I'm guessing you used a convenience method to initialize the array, or you autoreleased it, but you did not retain it within the window controller. If that's not the case, we can probably help you better if you posted some of your code relevant to this issue.
     
Mac Enthusiast
Join Date: Apr 2001
Location: Newton, MA, USA
Status: Offline
Reply With Quote
May 4, 2004, 11:11 AM
 
thanks all.

i did find it eventually, and it was something that was being released prematurely (i wound up leaving myself a trail of NSLogs to highlight my problem, and that found it). a dumb mistake (i'm good at those).

as for why i'm using notifications, it's due to the fact that the array resides in a document class and is being passed through the application controller class to a window controller class to a custom view which may or may not exist yet. at any rate, none of them can call a method of the document class. i did try making interlocking methods to play 'telephone' with all of them, but i suspect the same mistake probably caused me to abandon that effort.

thank you again...
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:27 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2