memory-management

Release a NSMutableArray when using ARC

对着背影说爱祢 提交于 2019-12-24 02:05:22
问题 I'm developing an iOS application using latest SDK and ARC. I have this variable: NSMutableArray* _previewImageBuffer; And this method: - (void)shutdown { [self stop]; _previewImageBuffer = nil; } Is _previewImageBuffer = nil; correct? If I do it, what happens with memory allocated in _previewImageBuffer`? Is this a memory leak? I want to release this object because I need to release the memory used by it. 回答1: What you're doing is exactly right. Nilifying an object instance variable under

How do you prevent leaks when raising an exception in init?

左心房为你撑大大i 提交于 2019-12-24 01:46:57
问题 Here's the situation. Let's say I have a class called MYFoo. Here's it's initializer: -init { self = [super init]; if (self) { // during initialization, something goes wrong and an exception is raised [NSException raise ...]; } return self; } Now somewhere else I want to use a MYFoo object, so I use a common pattern: MYFoo *foo = [[[MYFoo alloc] init] autorelease]; But what's going to happen is that, even if there's a try/catch around the 2nd part, a MYFoo object is going to be allocated, the

iOS - Not allocating too much memory at once

依然范特西╮ 提交于 2019-12-24 01:39:14
问题 Trying to get around a crash that is happening on some iOS devices, in conjunction with advice from Apple to "not cause allocation spikes". How can I change this code to not happen all at once? for (Item *item in self.items) { ItemView *itemView = [[ItemView alloc] initWithFrame:CGRectMake(xPos, kYItemOffsetIphone, kItemWidthIphone, kItemHeightIphone) ]; itemView.delegate = self; [itemView layoutWithData:item]; //this just adds an imageView and button [self.scrollView addSubview:itemView];

Monitor CPU and memory consumption of a specific processes in (Windows) C?

为君一笑 提交于 2019-12-24 01:25:10
问题 i would like to monitor the cpu and memory consumption of a given process in windows (nt architecture - xp,vista,win7), every few seconds to make a graph i have searched around but found only non C solutions only (java,c#,c++, etc) i know there is a PerformanceCounter class, but obviously it is not available in c. thanks 回答1: Win32 Performance Counters: http://msdn.microsoft.com/en-us/library/aa373083%28v=vs.85%29.aspx Developer Audience: Performance Counters is designed for use by C and C++

Why do we allocate 12 bytes for each variable?

陌路散爱 提交于 2019-12-24 01:18:25
问题 In visual Studio 2010 Professional (x86, Windows 7): ... more 00DC1362 B9 39 00 00 00 mov ecx,39h 00DC1367 B8 CC CC CC CC mov eax,0CCCCCCCCh 00DC136C F3 AB rep stos dword ptr es:[edi] 20: int a = 3; 00DC136E C7 45 F8 03 00 00 00 mov dword ptr [ebp-8],3 21: int b = 10; 00DC1375 C7 45 EC 0A 00 00 00 mov dword ptr [ebp-14h],0Ah 22: int c; 23: c = a + b; 00DC137C 8B 45 F8 mov eax,dword ptr [ebp-8] 00DC137F 03 45 EC add eax,dword ptr [ebp-14h] 00DC1382 89 45 E0 mov dword ptr [ebp-20h],eax 24:

Managing cache with memory mapped I/O

非 Y 不嫁゛ 提交于 2019-12-24 01:14:27
问题 I have a question regarding memory mapped io. Suppose, there is a memory mapped IO peripheral whose value is being read by CPU. Once read, the value is stored in cache. But the value in memory has been updated by external IO peripheral. In such cases how will CPU determine cache has been invalidated and what could be the workaround for such case? 回答1: That's strongly platform dependent. And actually, there are two different cases. Case #1. Memory-mapped peripheral. This means that access to

Memory profiling tool for Delphi?

廉价感情. 提交于 2019-12-24 00:58:30
问题 I set up a project and ran it, and looked at it in Process Explorer, and it turns out it's using about 5x more RAM than I would have guessed, just to start up. Now if my program's going too slowly, I hook it up to a profiler and have it tell me what's using all my cycles. Is there any similar tool I can hook it up to and have it tell me what's using all my RAM? 回答1: AQTime can help with that too. 回答2: What figures are you using from Process Explorer? "Memory Use" in Windows is not a

Will this Objective-C, nested NSArray cause a memory leak on iPhone?

♀尐吖头ヾ 提交于 2019-12-24 00:43:28
问题 NSArray *tLines = [[NSArray alloc] initWithObjects: [[NSArray alloc] initWithObjects:@"Matt", @"David", nil], [[NSArray alloc] initWithObjects:@"Bob", @"Ken", nil], nil]; self.lines = tLines; [tLines release]; I'm alloc ing NSArray s within an NSArray , will the nested arrays get released when I call [lines release]; ? 回答1: No, you should not do this. When you alloc the arrays, you need to release them. The containing array will handle memory management for its objects (retaining them when

Two pointer representation dilemma

不问归期 提交于 2019-12-24 00:40:00
问题 I don't understand how a machine can have more than one pointer representation. The following from GNU says if the target machine has two different pointer representations, the compiler won't know which representation to use for that argument. How is it possible? What is the relationship between the saying and #define SEM_FAILED ((sem_t*)-1) ? What does the latter do? I know it is null pointer which has constant value. But how is it represented in a memory since it points to -1? What about if

JFreeChart heap space

蓝咒 提交于 2019-12-24 00:39:51
问题 I'm just wondering if there's a way to stop JFreeChart thrashing the heap, or an alternative that doesn't do it so much. SpreadsheetDate , Millisecond and Day are taking up about 70 MB of the heap, but the garbage collector is probably getting thrashed too. They are, collectively, the biggest users of heap space in my app. There's also TimeSeriesDataItem which uses 12 MB. This is with recording things every 200 milliseconds or so, for all charts. I'm also updating / storing a fair few