Re: Newbie question: error in creating a NSData object using handle (Resource Management)
Re: Newbie question: error in creating a NSData object using handle (Resource Management)
- Subject: Re: Newbie question: error in creating a NSData object using handle (Resource Management)
- From: Kai <email@hidden>
- Date: Wed, 25 Jun 2008 17:58:12 +0200
On 25.6.2008, at 10:42, Tran Kim Bach wrote:
Thanks Ken and Kai for your very very quick responses
This is my first post in the list, I'm sorry for not clarifying my
problem.
Actually, the program stopped at the mentioned line.
In console, it said something like:
objc[2144]: FREED(id): message release sent to freed object=0x17d1d0
Ok, this looks like a standard overrelease problem. You posted too
little code to include the problematic point.
Best to read up on Cocoas Memory Management Rules and make sure, that
your Objective-C objects are not overreleased. Enabling Zombies can
help if you can’t find it in source.
(Note: retain counts are the same concept as AddRef and Release in
Microsofts COM, which you may know.)
Unless you have exceptionally many or large resources, I’d say you
won’t need to worry about running out of memory in the loop on todays
machines.
Best
Kai
PS: In case you have more questions about old-style resource access,
you’d better take them to Apples Carbon list. People there are
probably more understanding about the need to use time proven but no
longer fancy APIs. ;-)
This GDB was configured as "i386-apple-darwin"
(Error from the debugger) /users/...path_to_my_exe_file: No such
file or directory.
But I checked the exe file and it's absolutely there(in the bundle).
I tried an autorelease pool inside the loop, disposing of
datahandle.etc, but still got the same problem.
Now, when I confirmed the *dataHandle, it returned NULL
but I don't know why?
--Bach
On Wed, Jun 25, 2008 at 3:36 PM, Ken Thomases <email@hidden>
wrote:
On Jun 25, 2008, at 1:19 AM, Tran Kim Bach wrote:
Hi folks,I'm a newbie to Cocoa.
Recently, I'm working on a project relating to Resource Management.
In my project, there's a part that I'm reading through the resources
in a
resource file.
I'm using:
int count = CountResources( typeName );
to get all resource that has the type "typeName", then loop through
this
resource list to take resource data out.
for (n = 1; n <= count; n++)
{
Handle dataHandle = Get1IndResource( type1, n);
....
NSData *data = [NSData dataWithBytes: *dataHandle length:
GetResourceSizeOnDisk(dataHandle)]; // I GOT AN ERROR HERE
What do you mean "GOT AN ERROR"? What error? How did it manifest?
//using data
struct A_STRUCT aStruct;
memcpy(& aStruct,[data bytes], [data length]);
}
After several times looping through the list, I got an error in the
line
above.
But if I use data directly, like the following code, there is no error
occurred.
memcpy(&pgControlRes,*dataHandle, GetResourceSizeOnDisk(dataHandle));
Any suggestions for my problem.
I highly appreciate all your helps.
You don't show if you're:
1) Checking if dataHandle is NULL
2) Checking if *dataHandle is NULL
3) If (1) or (2), checking ResError()
4) Disposing of dataHandle with ReleaseResource()
Also, in the pseudo-code you provide, the NSData objects will
accumulate in the autorelease pool until some point after your "for"
loop. You can try using an autorelease pool inside the loop so that
the NSData objects are released after each iteration. You may just
be exhausting memory. For the case where you're not using NSData,
the memory exhaustion might not happen since you're not storing the
data twice in memory (once in the handle, once in the NSData), but
would if there were twice as many resources.
Cheers,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden