I have this:
enum Units { Pounds, Kilos };
struct Configuration
{
const Units units;
const char *name;
inline Configuration(Units pUnits, char *pName) : units(pUnits)
{
name = strdup(pName);
}
inline ~Configuration() { free((void *)name); }
};
I was passing one of these to a method like this:
Config...
I have been reading these slides about Java finalizers. In it, the author describes a scenario (on slide 33) whereby CleanResource.finalize() could be run by the finalizer thread while CleanResource.doSomething() is still running on another thread. How could this happen?
If doSomething() is a non-static method, then to execute that me...
Was recently reviewing some Java Swing code and saw this:
byte[] fooReference;
String getFoo() {
returns new String(fooReference);
}
void setFoo(String foo) {
this.fooReference = foo.getBytes();
}
The above can be useful to save on your memory foot print or so I'm told.
Is this overkill is anyone else encapsulating their St...
I have a real-life example that I have in my project below. My aim is to pick out the most likely phone number for SMS receptions, and only that (phone)number. All works well when I don't release memory at the end, but we can't have that, can we. My question is: Where (and how) is the correct way to release memory in the example below?
...
I'm working on an iPhone app that shows a map with multiple circle overlays on certain locations.
I'm running into serious memory issues and crashes when I add more than 6 circles and I zoom out far enough that they are all visible.
When I zoom in such that only 2 circles are visible, all is fine. When I remove the MKOverlays, everythin...
I have the following problem in a Visual C++ 9 program. There's a huge object that logically contains several subobjects. I can either store the subobjects inside the object or store pointers to subobjects allocated separately.
The key point here is that there's always one instance of suboject of each type in one outer object - it is al...
Hi guys, I'm new to iphone and objective-c development and want to ask if Clang Static Analyzer is enough for getting rid of memory leaks? I personally found the xcode "Leaks" tool rather difficult to use, besides I've seen some articles, where it reads that it will always show memory leaks, even if there are no any real leaks.
If I don...
This is a memory management question about c++ code.
using namespace std;
#include <iostream>
#include <string.h>
int main()
{
string a="first";
string *b= new string;
*b=a;
a="second";
cout << *b << ", " << a;
delete b;
return 0;
}
We can deallocate the blocks of memory that stored the string that b pointed to.
I'm assuming ...
Having some basic issues with managing the total memory from adding and removeing a uiviewcontroller - but only when i add an animation to it using CAtransition. I set up a simple scenario below of the situation:
I have a basic view controller that I init/alloc called IVC, and I add to the current uiController:
IN the header file it ...
Hello, I would like to know how memory allocation on the lowest levels works. For example if program wants to create some long array or anything else, how it will ask for the memory, how does the program ensure itself that it does not take memory same other program is using.
I would be very grateful if someone would bring some light fo...
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellId];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"ThemeCell" owner:self options:nil];
cell = self.themeCell;
self.themeCell = nil;
}
...
return cell;
My understanding is that self.themeCell = nil; should destroy the object sinc...
Recently, I started learning some Java. From what I've already learned about JVM it looks like JIT makes it pretty fast on operations requiring CPU cycles (i.e. calling a method) but also makes it hungry for memory. So when I need same output from same method as before, is it generally better approach to store the output from before in v...
I've seen this question asked dozens of times but never answered.
How do you resize a UIImage (specifically one returned from the UIImagePickerController camera). When I try any of the methods that are out there I get a memory spike between 20 and 40MB. It does go away but I know that on some hardware this is completely unacceptable.
I...
I release the MPMoviePlayerController but the memory allocation and the living objects are sill higher than before the object allocation. However if i reallocate the object it doesn't leak more.
My application actually uses alot of media files and the memory consumption it's high. I would like to free up completely the unneeded memory to...
I know in vast of the cases I don't have to release static variable. However the following is the code for my model:
+ (UIImage*)imageForTag
{
static UIImage *imgTag;
if(imgTag == nil)
{
NSString* imageName = [[NSBundle mainBundle]
pathForResource:@"tag" ofType:@"png"];
imgTag = [[...
When I run the following code, it slowly eats up my memory and even starts using swap:
long long length = 1024ull * 1024ull * 1024ull * 2ull; // 2 GB
db = [NSMutableData dataWithLength:length];
char *array = [db mutableBytes];
for(long long i = 0; i < length - 1; i++) {
array[i] = i % 256;
}
If I run it without the for c...
Dual Search(8896,0xb014b000) malloc: *** error for object 0x5a1e0f0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Thanks!
...
I hate asking memory management questions - all the good answers
are variations on RTFM. But this one is stumping me.
I have a (relatively) complex dictionary in my model class,
where each key points to an array of arrays. I constantly add and delete
items to it, depending on state. Each "item" is an array.
- (void)addToDictionary:(NSN...
I have a Python program that processes fairly large NumPy arrays (in the hundreds of megabytes), which are stored on disk in pickle files (one ~100MB array per file). When I want to run a query on the data I load the entire array, via pickle, and then perform the query (so that from the perspective of the Python program the entire array...
I have the following piece of code:
NSString *tempString = [[NSString alloc] initWithFormat:@"%d/%d/%d",day, month, year];
dateString = tempString;
[tempString release];
NSLog(@"retain count for datstring and tempstring is %d and %d",[dateString retainCount],[tempString retainCount]);
NSLog(@"%@ and %@",dateString, tempString)
Now ...