- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
Objective-C/ARC/内存管理问题已经在 SO 上被解决了,但这一个似乎与现有的略有不同。
我一直在尝试将 Objective-C 与 GNUStep 和 Clang 结合使用。我已经下载了库显然是 ARC 等现代 Objective-C 功能所必需的; block 工作并且 @autoreleasepool
连同相关的编译器标志被编译器接受。 AppKit GUI 工具包可以工作,队列调度程序也可以。
我的理解(如果正确的话)是 alloc
ed 对象会自动设置为在“父”堆栈框架的 @autoreleasepool
退出时释放,并且释放会减少引用计数。然而,编译器并不哀叹手动 [super dealloc]
并容忍手动 autoreleases
和 releases
,这意味着 ARC 甚至没有切换上。
有人可能会想象谷歌搜索 GNUStep ARC ~enable
会产生一些我遗漏的编译器标志,但事实并非如此。
这是一些示例代码。它是一个围绕 C99 bool
多维数组的对象包装器,它在 init
和 free
中被 malloc
编辑d 在 dealloc
中,我收集到的是 ARC 代码中 dealloc
的少数合法用途之一。请注意,在@autoreleasepool 完成后,dealloc
的puts
不会被调用,尽管其中只创建了一个引用。但是,手动release
或autorelease
效果很好。
#import <stdbool.h>
#import <stdio.h>
#import <stdlib.h>
#import <Foundation/Foundation.h>
@interface Area : NSObject {
bool *area;
size_t width, height;
}
- (id) initWithWidth:(size_t)aWidth height:(size_t)aHeight;
- (void) dealloc;
- (void) display;
@end
@implementation Area
- (id) initWithWidth:(size_t)aWidth height:(size_t)aHeight {
self = [super init];
width = aWidth;
height = aHeight;
area = malloc((sizeof *area) * aWidth * aHeight);
for (size_t y = 0; y < aHeight; ++y) {
for (size_t x = 0; x < aWidth; ++x) {
area[(aHeight * y) + (aWidth * x)] = true;
}
}
return self;
}
- (void) dealloc {
free(area);
puts("DEALLOCATED");
}
- (void) display {
for (size_t y = 0; y < height; ++y) {
putchar('|');
for (size_t x = 0; x < width; ++x) {
putchar(area[(height * y) + (width * x)]
? '#'
: ' ');
}
puts("|");
}
}
@end
int main(void)
{
@autoreleasepool {
id area = [[Area alloc] initWithWidth:10 height:10];
[area display];
}
return EXIT_SUCCESS;
}
我的编译脚本(一旦我开始工作,我将使用合适的 makefile):-
#!/bin/sh
INC_FLAG=`gnustep-config --variable=GNUSTEP_SYSTEM_HEADERS`
LIB_FLAG=`gnustep-config --variable=GNUSTEP_SYSTEM_LIBRARIES`
clang -o main main.m \
-I $INC_FLAG \
-L $LIB_FLAG \
\
-fblocks \
-fobj-arc \
-fconstant-string-class=NSConstantString \
-D_NATIVE_OBJC_EXCEPTIONS \
\
-pthread \
-lgnustep-base \
-ldispatch \
-lgnustep-gui \
-lobjc
我一直假设 autorelease
应该被推断为在 @autoreleasepool
中创建的对象。
提前致谢!
最佳答案
解决方案:Josh Caswell 指出我的编译器标志fobj-arc
应该是fobjc-arc
。鉴于 Clang 没有给出此标志无效的指示,我将把这个答案留给其他人。
关于Objective-C:如何在 GNUStep 中启用 ARC?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19895777/
我下载了 GNUStep并安装了它,但是我不确定在哪里可以找到 IDE。有谁知道什么程序可以用作 GNUStep IDE/从哪里获取它们?否则,有没有人知道有关如何创建和编译基本 GNUStep 程序
我正在 Windows 7 上的 VirtualBox 4.2.6 中运行 Ubuntu 12.04.1 LTS。我正在尝试从从 official repository on GitHub 下载的源代
我没有 Mac,是否可以在 Windows 上的 gnustep 中创建功能齐全的视频录制应用程序,然后执行必要的过程将其部署为 iPad 应用程序? 最佳答案 基本上,没有。当然,如果您使用 GNU
根据 another Stack Overflow post drain 消息是一个仅限 Apple 的调用: NSAutoreleasePool *pool = [[NSAutoreleasePoo
我刚刚制作了一个带有在线教程的makefile。 http://www.gnustep.org/resources/documentation/Developer/Base/ProgrammingMa
我下载并构建了 GNUstep libobjc2 1.6.1, svn co http://svn.gna.org/svn/gnustep/libs/libobjc2/1.6.1/ rep cd re
我使用 GNUStep 在 Windows 7 上使用 GCC 和 MinGW 编译 Objective-C。我希望能够从 Notepad++ 自动执行“make”指令(带有 make 文件),并将任
Objective-C/ARC/内存管理问题已经在 SO 上被解决了,但这一个似乎与现有的略有不同。 我一直在尝试将 Objective-C 与 GNUStep 和 Clang 结合使用。我已经下载了
[GNUStep installers] gnustep-system-0.24.2-setup.exe gnustep-core-0.25.0-setup.exe gnustep-devel-1.1
我查看了似乎相关的类,但不清楚是否有一个等同于用于 TCP/UDP 套接字的 Pipe 的类。 Socket 类描述似乎不只是执行创建和绑定(bind)端口以及设置监听所需的操作。目前,我已经在直接的
我想开始为 Windows 开发,但我想保留我在 NSFoundation 中使用的一些框架。我想使用 GNUStep 在 Windows 上构建它们,并可能使用 GNUStep 编写整个应用程序。
我正在尝试在 GNUstep 中使用 Objective-C 2.0 特性属性(使用 Windows)。 但是我不能使用@property 符号和@synthesize。 虽然我所有的代码都是正确的,
我正在尝试在 Linux (Ubuntu) 的 Objective-C 上构建 hello world。主程序 #import int main(void) { NSLog(@"asdasd
我有一个与此问题相关的问题 Unable to Compile Objective C using Gnustep on windows 我正在尝试在 Windows 上编译我的第一个 Objecti
我不认为我完全理解对象及其源文件如何与 Gorm 交互。当您对 NSObject 这样的类进行子类化时,它似乎会根据您如何使用导出和操作配置该对象来存储该对象的快照。 我的第一个问题是这个类存储在哪里
我已经下载了 gnustep core\gnustep system (for Windows) 和示例应用程序。当我从开始>所有程序> GNUstep> shell 运行 gnustep shell
我正在开发一个 Cocoa 应用程序,目的是使用 GNUstep 在 Windows 和 Linux 上使用它。到目前为止,我一直在避免使用 Objective-C 2.0 功能,但我真的很想至少开始
我是一个 Objective-C 新手,没有 Mac,但我仍然想练习这门语言。我听说在非 Mac 世界中,GNUstep 提供了 Cocoa 的一个很好的替代品,并且可以用作新的 objective-
嗨,我是初学者,学习 objective-c 。我发现错误“hello.m:1:34: Foundation/Foundation.h: No such file or directory”我开始知道
我正在探索在 Windows 上使用 GNUstep 编译应用程序。这是我的 main.m 文件: #import int main(int argc, const char *argv[]) {
我是一名优秀的程序员,十分优秀!