memory-management

Objective-C: Do you have to dealloc property objects before deallocating the parent object?

[亡魂溺海] 提交于 2019-12-23 10:10:51
问题 Let's say I have an object named "foo" with another object named "bar" as property. When "foo" deallocates, will it automatically remove all references to "bar" so that "bar" deallocates as well? or will "foo" deallocate and "bar" float in memory somewhere? even if all of "bar"'s references are defined in "foo". thanks in advance. 回答1: If the foo object has any retains on or copies of (thanks Dave) bar , for example when you declare the property as either one of these: @property (nonatomic,

Memory semantics of a computed array property?

久未见 提交于 2019-12-23 10:07:41
问题 This is for an app that allows users to tag things. Tags are just strings. An array of TagHolder objects holds a list of all tags in use in the app, with a boolean telling if the tag is selected, but this is an implementation detail. The external interface calls for two methods, selectedTags , and setSelectedTags: which return and accept an arrays of strings. I would like these two methods to work as accessors for a declared property selectedTags . Now, my question is: What would be the

Malloc on linux without overcommitting

心已入冬 提交于 2019-12-23 09:58:03
问题 How can I allocate memory on Linux without overcommitting, so that malloc actually returns NULL if no memory is available and the process doesn't randomly crash on access? My understanding of how malloc works: The allocator checks the freelist if there is free memory. If yes, the memory is allocated. If no, new pages are allocated from the kernel. This would be where overcommit can happen. Then the new memory is returned. So if there is a way to get memory from the kernel that is immediately

malloc() in Linux - “there is no guarantee that the memory really is available”?

淺唱寂寞╮ 提交于 2019-12-23 09:57:04
问题 I'm making a game where the world is divided into chunks of data describing the world. I keep the chunks in a dynamically allocated array so I have to use malloc() when initializing the world's data structures. Reading the malloc() man page, there is a Note as follows: By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. In case it turns out that the system is out of memory

Custom allocation using boost singleton_pool slower than default

六月ゝ 毕业季﹏ 提交于 2019-12-23 09:56:37
问题 I wrote custom operator new and operator delete for the class MyOrder. I am allocating memory using boost::singleton pool. Here is the program testing the performance, #include <boost/pool/singleton_pool.hpp> #include <boost/progress.hpp> #include <iostream> #include <new> #include <vector> class MyOrder{ std::vector<int> v1_; std::vector<double> v2_; std::string s1_; std::string s2_; public: MyOrder(std::string s1, std::string s2): s1_(s1), s2_(s2) {} ~MyOrder(){} static void * operator new

Memory Leak when retaining property

允我心安 提交于 2019-12-23 09:54:06
问题 I am trying to play a click sound on every button click in my app For that i created a Utility class whose .h and .m is as follows .h file @interface SoundPlayUtil : NSObject<AVAudioPlayerDelegate,AVAudioSessionDelegate> { AVAudioPlayer *audioplayer; } @property (retain, nonatomic) AVAudioPlayer *audioplayer; -(id)initWithDefaultClickSoundName; -(void)playIfSoundisEnabled; @end .m file @implementation SoundPlayUtil @synthesize audioplayer; -(id)initWithDefaultClickSoundName { self = [super

String initialization difference

╄→尐↘猪︶ㄣ 提交于 2019-12-23 09:48:58
问题 Firstly apologies if this a very basic question, I'm just curious to know the difference between the following string definitions String x= "hello"; String y = new String("hello"); I knew that in java String is a Class its neither a primitive nor a Wrapper(Correct me if this a misconception). Consider a class A, I've seen the following declarations for any class so far. i think A c; is valid and A a = new A(); is also valid. I'm confused with A a ="xyz"; this is how we declared a String as in

Allocating a buffer of more a page size on stack will corrupt memory?

只谈情不闲聊 提交于 2019-12-23 09:37:12
问题 In Windows, stack is implemented as followed: a specified page is followed committed stack pages. It's protection flag is as guarded. So when thead references an address on the guared page, an memory fault rises which makes memory manager commits the guarded page to the stack and clean the page's guarded flag, then it reserves a new page as guarded. when I allocate an buffer which size is more than one page(4KB), however, an expected error haven't happen. Why? 回答1: Excellent question (+1).

Avoid UIImage’s imageNamed - memory management

本秂侑毒 提交于 2019-12-23 09:33:27
问题 I was going through this link, where I came across a point Avoid UIImage’s imageNamed . For what reason we should avoid this? 回答1: In Apple WWDC videos section they are saying imageNamed leaked once..But no longer do..I remember seeing the video, but cant remember which video section..It was in 2010 WWDC I think..ImageNamed still caches images..From documentation of imageNamed.. This method looks in the system caches for an image object with the specified name and returns that object if it

Does VC++ support _mm_malloc?

六月ゝ 毕业季﹏ 提交于 2019-12-23 09:06:24
问题 Does Visual Studio C++ 2008/2010 support _mm_malloc officially? It is defined in malloc.h but I can't find its description in the MSDN library. 回答1: Doesn't answer your question directly, but I think you're suppose to use _aligned_malloc. If my understanding is correct, _mm_malloc is for Intel compilers. 回答2: _mm_malloc/_mm_free supported in Visual Studio 2013 with using the <malloc.h> header. 回答3: See Equivalent C code for _mm_ type functions and, more distantly related, How to allocate