Objective-C Runtime

RSS for tag

The Objective-C runtime is a runtime library that supports the dynamic properties of the Objective-C language.

Objective-C Runtime Documentation

Posts under Objective-C Runtime tag

20 Posts
Sort by:
Post not yet marked as solved
1 Replies
119 Views
Intermittent Failures Occur During macOS Build Execution on Bamboo. Below is an Extract from the Failure Logs. Note: Please note that within our larger Bamboo build environment, several Xcode projects are constructed. Failures occur intermittently across various Xcode projects each time the Bamboo build is initiated. Therefore, these failures are not specific to any particular Xcode project. It's important to emphasize that the Xcode project mentioned, "myProject.xcodeproj," is used purely as a placeholder or example in this context. which 'xcodebuild' VALID_ARCHS="x86_64 arm64" ARCHS="x86_64" -project “”myProject.xcodeproj"" -alltargets -configuration "Release" -UseModernBuildSystem=NO build 08-Feb-2024 09:53:00 Command line invocation: build 08-Feb-2024 09:53:00 /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild "VALID_ARCHS=x86_64 arm64" ARCHS=x86_64 -project myProject.xcodeproj -alltargets -configuration Release -UseModernBuildSystem=NO build 08-Feb-2024 09:53:00 build 08-Feb-2024 09:53:00 User defaults from command line: build 08-Feb-2024 09:53:00 IDEPackageSupportUseBuiltinSCM = YES build 08-Feb-2024 09:53:00 UseModernBuildSystem = NO build 08-Feb-2024 09:53:00 build 08-Feb-2024 09:53:00 Build settings from command line: build 08-Feb-2024 09:53:00 ARCHS = x86_64 build 08-Feb-2024 09:53:00 VALID_ARCHS = x86_64 arm64 build 08-Feb-2024 09:53:00 error 08-Feb-2024 09:53:01 objc[39076]: thread is already initializing this class! error 08-Feb-2024 09:53:01 make[6]: *** [compile] Abort trap: 6
Posted Last updated
.
Post not yet marked as solved
3 Replies
261 Views
I'm working on an FFI for working with ObjectiveC/Foundation/Metal. AFAIU, as many APIs create and autorelease objects, I need to ensure that an NSAutoreleasePool is active when calling into these APIs. So I've created a wrapper that basically mimics @autoreleasepool by creating and initializing an NSAutoreleasePool, running some code, and then draining the pool. So far so good; I'm using this functionality around most of my entry points into the ObjectiveC world. There's two issues I don't understand though. The first is that NSAutoreleasePool initialization seems to require an active autorelease pool, which seems like a chicken-and-egg problem. Running with OBJC_DEBUG_MISSING_POOLS=YES and breaking on objc_autoreleaseNoPool, I see: objc[30336]: MISSING POOLS: (0x1e2e89c40) Object 0x6000007e0050 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug (lldb) bt objc_autoreleaseNoPool at /usr/lib/libobjc.A.dylib (unknown line) _ZN19AutoreleasePoolPage17autoreleaseNoPageEP11objc_object at /usr/lib/libobjc.A.dylib (unknown line) _ZN19AutoreleasePoolPage4pushEv at /usr/lib/libobjc.A.dylib (unknown line) _CFAutoreleasePoolPush at /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (unknown line) -[NSAutoreleasePool init] at /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (unknown line) macro expansion at /Users/tim/Julia/pkg/ObjectiveC/src/syntax.jl:163 [inlined] NSAutoreleasePool at /Users/tim/Julia/pkg/ObjectiveC/src/foundation.jl:427 The second, related problem is that some APIs that are called by Metal from a background thread I don't control: (lldb) bt * thread #11, queue = 'com.Metal.CompletionQueueDispatch', stop reason = breakpoint 1.1 * frame #0: 0x000000018c21b9e8 libobjc.A.dylib`objc_autoreleaseNoPool frame #1: 0x000000018c1eb99c libobjc.A.dylib`AutoreleasePoolPage::autoreleaseNoPage(objc_object*) + 252 frame #2: 0x000000018c21c9ec libobjc.A.dylib`AutoreleasePoolPage::push() + 76 frame #3: 0x00000001aaef9694 IOGPU`-[IOGPUMetalBuffer dealloc] + 104 frame #4: 0x00000001f83554e4 AGXMetalG15X_B0`-[AGXBuffer dealloc] + 44 frame #5: 0x00000001f837eb98 AGXMetalG15X_B0`-[AGXG15XFamilyBuffer dealloc] + 76 frame #6: 0x000000019687c1c4 Metal`MTLResourceListChunkFreeEntries(MTLResourceListChunk*) + 64 frame #7: 0x000000019674e2b0 Metal`-[MTLResourceList releaseAllObjectsAndReset] + 72 frame #8: 0x00000001aaefbd10 IOGPU`IOGPUMetalCommandBufferStorageReset + 36 frame #9: 0x00000001aaefbcac IOGPU`IOGPUMetalCommandBufferStorageDealloc + 76 frame #10: 0x00000001aaefa130 IOGPU`-[IOGPUMetalCommandBuffer didCompleteWithStartTime:endTime:error:] + 240 frame #11: 0x000000019674dce4 Metal`-[_MTLCommandQueue commandBufferDidComplete:startTime:completionTime:error:] + 108 frame #12: 0x00000001aaf03b54 IOGPU`IOGPUNotificationQueueDispatchAvailableCompletionNotifications + 128 frame #13: 0x00000001aaf03c60 IOGPU`__IOGPUNotificationQueueSetDispatchQueue_block_invoke + 64 frame #14: 0x000000018c4049d0 libdispatch.dylib`_dispatch_client_callout4 + 20 frame #15: 0x000000018c420c5c libdispatch.dylib`_dispatch_mach_msg_invoke + 468 frame #16: 0x000000018c40bd28 libdispatch.dylib`_dispatch_lane_serial_drain + 368 frame #17: 0x000000018c421998 libdispatch.dylib`_dispatch_mach_invoke + 444 frame #18: 0x000000018c40bd28 libdispatch.dylib`_dispatch_lane_serial_drain + 368 frame #19: 0x000000018c40ca08 libdispatch.dylib`_dispatch_lane_invoke + 432 frame #20: 0x000000018c40bd28 libdispatch.dylib`_dispatch_lane_serial_drain + 368 frame #21: 0x000000018c40c9d4 libdispatch.dylib`_dispatch_lane_invoke + 380 frame #22: 0x000000018c41761c libdispatch.dylib`_dispatch_root_queue_drain_deferred_wlh + 288 frame #23: 0x000000018c416e90 libdispatch.dylib`_dispatch_workloop_worker_thread + 404 frame #24: 0x000000018c5b2114 libsystem_pthread.dylib`_pthread_wqthread + 288 (lldb) c Process 26902 resuming objc[26902]: MISSING POOLS: (0x1e2e89c40) Object 0x14c8a2400 of class AGXG15SDevice autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug Again, I'm not sure how I'm supposed to run this under an autorelease pool.
Posted
by maleadt.
Last updated
.
Post not yet marked as solved
3 Replies
309 Views
I have a class category declared and compiled in a mac os static lib: #import <Foundation/Foundation.h> @interface NSNumber(MyExtension) -(NSString *)CallMe; @end then this staticLib is added to a mac console app in XCode and used: #import <Foundation/Foundation.h> #import "MacStaticLib.h" int main(int argc, const char * argv[]) { @autoreleasepool { NSNumber *one = [NSNumber numberWithInt:12]; NSLog(@"%@",[one CallMe]); } return 0; } Compiles fine but fails in runtime, unrecognized selector 'CallMe' send to instance... what's wrong or what I missed? Thanks!!
Posted
by wirex.
Last updated
.
Post not yet marked as solved
3 Replies
339 Views
Hello. iOS 15 and its version of Swift had an issue with applying class level annotations, such as @available to the members of its class. When we attempt to use our Objective-C library to get the class, if there are things inside the class not available on iOS 15, then the call to objc_getClass crashes with EXC_BAD_ACCESS. This appears to have been fixed on iOS 16 and newer, however, as we still support iOS 15, is there a better workaround than having to annotate every needed member of the class with @available, instead of being able to use the class level annotation?
Posted Last updated
.
Post not yet marked as solved
4 Replies
423 Views
I refer to Google's ESF project code to handle NOTIFY events, but after my notifyQueue is set to QOS_CLASS_BACKGROUND, the process memory gets larger when a lot of events occur. Is there any way to fix this without affecting performance The code is as follows: notifyQueue = dispatch_queue_create("notify",dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_CONCURRENT_WITH_AUTORELEASE_POOL,QOS_CLASS_BACKGROUND, 0)); if (msg->action_type == ES_ACTION_TYPE_NOTIFY) { es_message_t *copied_msg = [self copy_message:msg]; if (!copied_msg) { return; } dispatch_async(self->_notifyQueue, ^{ @autoreleasepool { [self handle:copied_msg]; [self free_message:copied_msg]; } }); }
Posted
by c4m3l.
Last updated
.
Post not yet marked as solved
1 Replies
320 Views
i’ve seen evidence that UIViewController has logic to prevent its dealloc/deinit methods from running on a background thread. what seems to occur is that, if the last strong reference to a UIVC is zeroed off the main thread, then the VC is logically marked as ‘deallocating’, but actual invocation of dealloc/deinit is enqueued to the main queue. during the window of time between the beginning and end of this asynchronous deallocation, some strange issues can occur. in particular, if the deallocating VC is a parent view controller, then its children can still access it via their parent property. despite this property being marked as weak, a non-nil parent VC reference will be returned. if a weak reference is attempted to be stored to the parent, you get a runtime crash immediately to the effect of: Cannot form weak reference to instance (0x1234) of class <some-UIVC-sublass>... surprisingly, if you load the reference via the objc runtime's objc_loadWeak method, you'll get nil, but no crash. unsurprisingly, if a strong reference to the deallocating parent is stored and persists past its dealloc invocation, you’ll generally end up with a segmentation violation if the reference is accessed. i imagine the UIVC source is quite complex and there are probably good reasons to try and ensure deallocation only ever occurs on the main thread, but it seems surprising that simply passing view controller variables across threads could lead to exposing unsafe references like this. is this behavior expected? assuming not, i've preemptively filed feedback FB13478946 regarding this issue. attached is some sample code that can reliably reproduce the unexpected behavior. UIKitAsyncDeallocCrashTests.swift
Posted
by jamie_sq.
Last updated
.
Post not yet marked as solved
2 Replies
339 Views
xcode :Version 15.0.1 (15A507) MACOS:13.6.1 (22G313) thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0) frame #0: 0x0000000000000000 frame #1: 0x000000010482ec60 FUSTAKitOUTLINED_FUNCTION_3 + 580 frame #2: 0x0000000104430810 dyldImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 424 frame #3: 0x0000000104430bd8 dyldImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 52 frame #4: 0x000000010442b600 dyldImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 536 frame #5: 0x000000010442b56c dyldImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 388 frame #6: 0x0000000104429878 dyldImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 184 frame #7: 0x0000000104429940 dyldImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 92 frame #8: 0x000000010441a6d8 dylddyld::initializeMainExecutable() + 216 frame #9: 0x000000010441f928 dylddyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 5216 frame #10: 0x0000000104419208 dylddyldbootstrap::start(dyld3::MachOLoaded const*, int, char const**, dyld3::MachOLoaded const*, unsigned long*) + 396 frame #11: 0x0000000104419038 dyld`_dyld_start + 56 when I run a Test app(Just create with xcode Version 15.0.1 (15A507),without any extra code) depency FUSTAKit.framework packed by xcode Version 15.0.1 (15A507), i find this error。 but used xcode 14.2 pack FUSTA Kit.framework , everything is normal 。
Posted Last updated
.
Post not yet marked as solved
3 Replies
790 Views
Hello, I am attempting to track down a crash that isn't giving me a lot of information (crash log included below). Here is what I know so far: According to Apple documentation, a crash in objc_msgSend is due to a zombie object. So I have been trying to recreate the crash with zombies enabled, without success. The address of the object being messaged is 0x0000000000000010, a suspect value. It's always 0x10, across thousands of crash reports with slightly differing stack traces and circumstances. That makes me wonder if the runtime is trying to tell me something with that address, but I have been unable to find any documentation to that effect. We have internal analytics that suggest that the crash always happens after the user activates the system PIP video player, and usually also after backgrounding the app. It is also common (though not universal) that the crash occurs after the user has paused the video (and sometimes resumed it). This post is a bit of a Hail Mary; I'm hoping that maybe someone on here will see something I missed, because I have exhausted most of my own avenues of investigation. Many thanks for any help you can provide. 2023-11-30_07-16-00.4347_-0800-ffd5dc1a3d2ca628e1761ccfec5fe79f223d099e.crash
Posted
by ElFrijol.
Last updated
.
Post marked as solved
1 Replies
342 Views
Hello, here is the block where arrayController is nil : { NSData * data; NSError * error; Class klass; if(_arrayController != nil) // nil ! { selected = [_arrayController selectedObjects]; arranged = [_arrayController arrangedObjects]; if([selected count] &gt; 0) { _currentObject = [selected objectAtIndex:0]; if(_currentObject != nil) { data = [_currentObject valueForKey:kVrRoot]; klass = [NSMutableDictionary class]; _vrRoot = [NSKeyedUnarchiver unarchivedObjectOfClass:klass fromData:data error:&amp;error]; }else { _vrRoot = [NSMutableDictionary new]; data = [NSKeyedArchiver archivedDataWithRootObject:_vrRoot requiringSecureCoding:YES error:&amp;error]; } } } } I use this for years so I don't no what's wrong.
Posted Last updated
.
Post not yet marked as solved
3 Replies
354 Views
Hello, We have a legacy project that has a NSData category. This category is used to add a new method called "base64EncodedString" that we use for a custom base 64 encoding. Up until iOS 17, everything worked and we had no issue with it. This how we use it: NSString* text = @"This is the string we want to encode"; NSString* strArrRequests64 = [[text dataUsingEncoding:NSUTF8StringEncoding] base64EncodedString]; We have a breakpoint in our implementation of base64EncodedString - (NSString *)base64EncodedString { size_t outputLength; char *outputBuffer = ....; NSString *result = [[[NSString alloc] initWithBytes:outputBuffer length:outputLength encoding:NSUTF8StringEncoding] autorelease]; free(outputBuffer); return result; } The strange thing is that we use this method for several calls in our app. In 80% of the cases it triggers the breakpoint and the encoding works as intended, but some calls do not and the encoding does not happen. We have checked the class of [text dataUsingEncoding:NSUTF8StringEncoding] and for all calls is "NSMutableConcreteData". This is a breaking change for iOS17 and it affects a lot of our clients. We have a solution for this particular case, but there are more categories inside our library which can be affected by this issue. Please advise.
Posted Last updated
.
Post not yet marked as solved
0 Replies
284 Views
Below is the implementation of the object_cxxDestructFromClass method. the line below the for loop if (!cls->hasCxxDtor()) return; Some questions: If a subclass inherits a parent class, and one of the middle classes does not have a CxxDtor, but the parent class does, will there be any problems with the release of the instance? static void object_cxxDestructFromClass(id obj, Class cls) { void (*dtor)(id); // Call cls's dtor first, then superclasses's dtors. for ( ; cls; cls = cls->getSuperclass()) { if (!cls->hasCxxDtor()) return; dtor = (void(*)(id)) lookupMethodInClassAndLoadCache(cls, SEL_cxx_destruct); if (dtor != (void(*)(id))_objc_msgForward_impcache) { if (PrintCxxCtors) { _objc_inform("CXX: calling C++ destructors for class %s", cls->nameForLogging()); } (*dtor)(obj); } } }
Posted
by cocoas.
Last updated
.
Post not yet marked as solved
4 Replies
1.6k Views
I was migrating from Xcode 14 -> 15, and noticed that my code was failing with dyld[46534]: Symbol not found: _OBJC_CLASS_$_NSError I was able to debug the problem to some old objective c code, as documented in this thread: https://github.com/RonRadtke/react-native-blob-util/issues/273 The error seems to stem from this particular try catch block @try { // Some code } @catch(NSError *er) { // handle error } When I convert the code to catch an NSException instead, the runtime error goes away. Understandably, according to the apple docs, it should be throwing an NSException in the first place, but the documents do say Important: Although you can throw and catch objects other than NSException objects, the Cocoa frameworks themselves might only catch NSException objects for some conditions. So if you throw other types of objects, the Cocoa handlers for that exception might not run, with undefined results. (Conversely, non-NSException objects that you throw could be caught by some Cocoa handlers.) For these reasons, it is recommended that you throw NSException objects only, while being prepared to catch exception objects of all types. So it seems like this should not have produced a runtime error. I wanted to flag this in case the underlying code behind the @try @catch changed unintentionally.
Posted
by mojolili.
Last updated
.
Post not yet marked as solved
3 Replies
627 Views
Hi Experts, I am working on a application where I am calling Objective-C Core WLAN API from golang with below code, darwin_lib.m void ConnectWiFi(char * cInterfacename, char * cSSID, char * cSecurity, char *cSubsecurity, char * cPassphrase, char * cOnexuser, char * cOnexpass) { @autoreleasepool { NSString * interfacename = [[NSString alloc] initWithUTF8String:cInterfacename]; NSString * ssid = [[NSString alloc] initWithUTF8String:cSSID]; NSString * security = [[NSString alloc] initWithUTF8String:cSecurity]; NSString * subsecurity = [[NSString alloc] initWithUTF8String:cSubsecurity]; NSString * passphrase = [[NSString alloc] initWithUTF8String:cPassphrase]; NSString * onexuser = [[NSString alloc] initWithUTF8String:cOnexuser]; NSString * onexpass = [[NSString alloc] initWithUTF8String:cOnexpass]; NSError * connecterr = nil; CWWiFiClient * cwwificlient = [CWWiFiClient sharedWiFiClient]; CWInterface *a = [cwwificlient interfaceWithName:interfacename]; NSSet<CWNetwork *> * network = [a scanForNetworksWithName:ssid error:&connecterr]; **** some more code ***** BOOL result = [a associateToEnterpriseNetwork:network.anyObject identity:nil username:onexuser password:onexpass error:&connecterr]; main.go package main // #cgo CFLAGS: -x objective-c // #cgo LDFLAGS: -framework CoreWLAN // #cgo LDFLAGS: -framework Foundation // #include "clib.h" import "C" import "fmt" func main() { var status C.int = C.ConnectWiFi() time.Sleep(20) *** some more code and long running process *** } Now what I am trying to understand here from memory release point of view is, Is object created in C code will be freed once I reach time.Sleep(20) e.g cwwificlient a spcifically to Core WLAN side or do I have to call release specifically on object? I tried calling release on cwwificlient and program is crashing on second execution, not sure why it would crash on only second execution, why not first time itself? I tried calling release on a and program is not crashing. Do I have to free all the Core WLAN related object myself or autoreleasepool will take care of it? As whole code is inside autoreleasepool, will all the objects be released on it's own even though function is being called from go code? As go's garbage collector has no idea how many objects C code created so go's garbage collector won't be of any help here Is autoreleasepool, can also take care of releasing any alloc object e.g ssid created inside C code ?
Posted
by tejask.
Last updated
.
Post not yet marked as solved
4 Replies
1.2k Views
I ran across the following crash while using one of our apps. The app crashes since the recent iOS 17 beta builds. The code crashes when using valueForKey on an NSArray with objects that implement NSCopying. like: [@[[Sample new]] valueForKey:@"copy"]; or: [[Sample new] valueForKey:@"copy"]; header: @interface Sample : NSObject<NSCopying> - (Sample *)copy; - (Sample *)copyWithZone:(nullable NSZone *)zone; @end implementation: @implementation Sample - (Sample *)copy { return [super copy]; } - (Sample *)copyWithZone:(nullable NSZone *)zone { return self; } @end Any idea why this might be happening? I have created a feedback too: FB12819891
Posted
by Fabasoft.
Last updated
.
Post not yet marked as solved
2 Replies
574 Views
Any ideas on how to root cause this? Started since iOS 15.x, affecting only small percentage of users. Apple crash report attached. Thanks! 2023-07-25_15-08-32.4590_-0400-444d5ea058bb103160c275742f01d7f130e02661.crash
Posted
by dimager.
Last updated
.
Post not yet marked as solved
2 Replies
2.0k Views
My application is currently crashing in production in iPhone devices running iOS 15.x. The app will work as normal while running developer mode, enterprise builds and Test Flight builds. Unfortunately, I am unable to reproduce this issue even app is downloaded from the app store. I observed crash is happening at main.m. Can someone help me to reproduce this issue? How to read this crash log file? Please find the crash log details attached. 2022-03-04_14-15-23.6227_+0900-a1899fd803a4ed683466702be71b9d224b4cd5bc.crash
Posted Last updated
.
Post not yet marked as solved
3 Replies
1.7k Views
After the user upgrades to iOS16, our app receives a few crash reports attempted to dereference garbage pointer on iOS16. These issues only happen on iOS16. Here we provide some typical cases. It may be a system bug! Case A 0 libobjc.A.dylib _cache_getImp 1 libobjc.A.dylib _class_respondsToSelector_inst 2 Foundation __NSDescriptionWithStringProxyFunc 3 CoreFoundation ___CFStringAppendFormatCore 4 CoreFoundation __CFStringCreateWithFormatAndArgumentsReturningMetadata 5 CoreFoundation __CFStringCreateWithFormatAndArgumentsAux2 6 Foundation +[NSString stringWithFormat:] Case B 0 libobjc.A.dylib _cache_getImp 1 libobjc.A.dylib _object_getMethodImplementation 2 CoreFoundation __NSIsNSString 3 CoreFoundation -[NSTaggedPointerString isEqual:] 4 CoreFoundation -[__NSDictionaryM objectForKey:]
Posted
by codefei.
Last updated
.
Post not yet marked as solved
2 Replies
988 Views
When I have a property like this: @property (nonatomic, readonly, copy) NSURL *sourceURL; And then I call: NSURL *url = self.sourceURL; Assuming that ARC is disabled, to ensure this object does not leak, must I manually release url? If so, how come I don't have to with: NSURL *url = [NSURL URLWithString:@"http://www.apple.com"]; NSURL *absURL = url.absoluteURL; Despite the absoluteString property also being readonly and copy: As per Apple: @property(nullable, readonly, copy) NSURL *absoluteURL;
Posted
by pi1024e.
Last updated
.