nsautoreleasepool

autoreleasepool was not declared in this scope error

 ̄綄美尐妖づ 提交于 2020-01-22 02:55:08
问题 My project is in XCode 4.2. This project compiles for a regular debug build. But when I change the build type to profile (I want to profile memory usage), I get the error from this objective-c++ c++ class: /Volumes/mchinen/scm/Voicer/FilterAudioMixer.mm:53: error: stray '@' in program /Volumes/mchinen/scm/Voicer/FilterAudioMixer.mm: In member function 'void FilterAudioMixer::WriteToBuffer(SInt16*, int)': /Volumes/mchinen/scm/Voicer/FilterAudioMixer.mm:53: error: 'autoreleasepool' was not

Autorelease pools in Objective-C - release main AutoreleasePool?

↘锁芯ラ 提交于 2020-01-12 07:35:09
问题 By my understanding, when an object is sent an autorelease message, if no autorelease pools exist other than the one in main.m , the object gets placed in the one in main.m . Assuming this is correct, I have a couple of questions: 1) Do all autoreleased objects stay in that pool until the termination of the app? 2) If 1 is true, does creating an autoreleased object without a local autorelease pool (therefore placing that object in the main.m pool) keep that object in memory until termination

NSAutoreleasePool. When is it appropriate to create a new autorelease pool?

拟墨画扇 提交于 2020-01-01 10:56:25
问题 On iOS/CocoaTouch I often see code that creates a new instance of NSAutoreleasePool within a method. I recently saw one within an NSOperation. What are the ground rules for setting up a new instance of NSAutoreleasePool? Why is this preferable to simply relying on the pre-existing release pool created in main.m? Thanks, Doug 回答1: You can use a new autorelease pool whenever you want, but it is not always beneficial. It is required whenever you start a new thread or objects autoreleased in that

Under ARC, is it still advisable to create an @autoreleasepool for loops?

巧了我就是萌 提交于 2019-12-28 13:06:26
问题 Let's say that I have a loop that returns a bunch of autoreleased NSData objects... NSData* bigData = ... while(some condition) { NSData* smallData = [bigData subdataWithRange:...]; //process smallData } Under ARC, should I still wrap an @autoreleasepool around the while condition? NSData* bigData = ... @autoreleasepool { while(some condition) { NSData* smallData = [bigData subdataWithRange:...]; //process smallData } } The reason why I'm asking is I see the living allocation count in

Under ARC, is it still advisable to create an @autoreleasepool for loops?

≯℡__Kan透↙ 提交于 2019-12-28 13:05:42
问题 Let's say that I have a loop that returns a bunch of autoreleased NSData objects... NSData* bigData = ... while(some condition) { NSData* smallData = [bigData subdataWithRange:...]; //process smallData } Under ARC, should I still wrap an @autoreleasepool around the while condition? NSData* bigData = ... @autoreleasepool { while(some condition) { NSData* smallData = [bigData subdataWithRange:...]; //process smallData } } The reason why I'm asking is I see the living allocation count in

Threads and autoreleasepool questions

感情迁移 提交于 2019-12-24 16:18:15
问题 As I understand there are several ways to send tasks to be performed in threads. The most common ones that I use are: 1) performSelector:withObject:afterDelay: 2) performSelectorOnMainThread:withObject:waitUntilDone: 3) performSelectorInBackground:withObject: 4) [NSThread detachNewThreadSelector:toTarget:withObject:] My first question is, what is the difference between 1) and 2), besides the obvious parameter differences? Are they actually both working in the Main thread (whose autorelease

Objective-C: Allocation in one thread and release in other

拥有回忆 提交于 2019-12-24 09:09:51
问题 I am doing this in my Main Thread: CCAnimation *anim; //class variable [NSThread detachNewThreadSelector:@selector(loadAimation) toTarget:self withObject:nil]; In loadAimation: -(void) loadAnimation { NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; anim = [[CCAnimaton alloc] init]; [autoreleasepool drain]; } And in main thread I release it: [anim release]; Now I want to ask if this is fine regarding memory management. 回答1: It's possible to allocate an object in one

Swift closures in autorelase pool accessing methods without self

余生颓废 提交于 2019-12-23 18:04:13
问题 This is sample code func anyMethod() { // Nothing here } var myVariable = "" autoreleasepool { anyMethod() // This should show error print(myVariable) // This should show error } it should show error Call to method 'anyMethod' in closure requires explicit 'self.' to make capture semantics explicit But I am able to call anyMethod without self, I wonder why this not showing error Why this is working without self ? EDIT Copy paste this class to re-produce import Foundation import UIKit class

Do I win memory by explicitly disposing imageView.Image?

戏子无情 提交于 2019-12-22 17:35:24
问题 I have this code in my app: var newImage = // ... if (imageView.Image != null && imageView.Image != newImage) imageView.Image.Dispose (); imageView.Image = newImage; I have three related questions: Does it immediately release the memory occupied by the previous imageView.Image ? If it does, is there a cleaner solution? Does this have anything to do with NSAutoreleasePool ? 回答1: Does it immediately release the memory occupied by the previous imageView.Image? Not immediately but it should be

How to use NSAutoreleasePool in AppleScriptObjC

旧城冷巷雨未停 提交于 2019-12-20 04:37:18
问题 I am wondering how to stop another function from a background function. In addition, I have to drain NSAutoreleasePool, but I don't know how to do it. I think this app sometimes freeze if I don't release pool. property i : 0 property myLabel : missing value on myStartButtonHandler_(sender) my performSelectorInBackground_withObject_("start", missing value) -- This code prevents "Stop" Button from freezing. end myStartButtonHandler_ on myStopButtonHandler_(sender) -- I want to stop start()