I have this memory leak that has been very stubborn for the past week or so. I have a class method I use in a class called "ArchiveManager" that will unarchive a specific .dat file for me, and return an array with it's contents. Here is the method:
+(NSMutableArray *)unarchiveCustomObject
{
NSMutableArray *array = [NSMutableArray a...
Hi, I have a newbie question regarding when to release the elements of a NSArray. See following pseudo code:
NSMutalbeArray *2DArray = [[NSMutableArray alloc] initWithCapacity:10];
for (int i=0;i<10;i++) {
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:5];
for (int j=0;j<5;j++) {
MyObject *obj = [[MyObject allo...
I am leaking memory on this:
my custom class:
+ (id)vectorWithX:(float)dimx Y:(float)dimy{
return [[[Vector alloc] initVectorWithX:dimx Y:dimy] autorelease]; }
- (Vector*)add:(Vector*)q {
return [[[Vector vectorWithX:x+q.x Y:y+q.y] retain] autorelease]; }
in app delegate I initiate it:
Vector *v1 = [[Vector alloc] initVector];
Vec...
Now, I'm a user of ruby-on-rails 2.3.5.
I want to override the method of "session_store" in ActionController::SessionManagement::ClassMethods.
In my overrides, I need the "request" object which has a lot of useful information such as host name, domain name, etc...
Do you have any idea to get the "request" object in that method.
My rails ...
I understand that memory has to be reserved before being committed. And when it's reserved, no other process can use it. However reserved memory does not count against available RAM. But shouldn't it? Because if no one else can use it, then what good is it being "available"?
Or is there some bigger difference?
...
I have a tab-separated data file with a little over 2 million lines and 19 columns.
You can find it, in US.zip: http://download.geonames.org/export/dump/.
I started to run the following but with for l in f.readlines(). I understand that just iterating over the file is supposed to be more efficient so I'm posting that below. Still, wit...
See title. To be more specific, I am trying to return the mutableCopy of an object, however it's returned with a retainCount of 1 and I am worrying that it will leak.
...
I am having this problem with the NSMutableDictionary where the values are not coming up.
Snippets from my code look like this:
//Data into the Hash and then into an array
yellowPages = [[NSMutableArray alloc] init];
NSMutableDictionary *address1=[[NSMutableDictionary alloc] init];
[address1 setObject:@"213 Pheasant CT" forKey: @"S...
My function is being passed a struct containing, among other things, a NULL terminated array of pointers to words making up a command with arguments.
I'm performing a glob match on the list of arguments, to expand them into a full list of files, then I want to replace the passed argument array with the new expanded one.
The globbing is...
My program uses a third party dynamic link library that has huge memory leaks inside. Both my program and the library are Visual C++ native code. Both link to the Visual C++ runtime dynamically.
I'd like to force the library into another heap so that all allocations that are done through the Visual C++ runtime while the library code is ...
I am new to C++. I am getting HEAP CORRUPTION ERROR. Any help will be highly appreciated. Below is my code
class CEntity
{
//some member variables
CEntity(string section1,string section2);
CEntity();
virtual ~CEntity();
//pure virtual function ..
virtual CEntity* create()const = 0;
};
I derive CLine from CEntity as...
Is deleting a pointer same as freeing a pointer (that deallocates the memory)?
...
Looks like dynamic memory allocation without garbage collection is a way to disaster. Dangling pointers there, memory leaks here. Very easy to plant an error that is sometimes hard to find and that has severe consequences.
How are these problems addressed when mission-critical programs are written? I mean if I write a program that contr...
I'm working on a texture management and animation solution for a small side project of mine. Although the project uses Allegro for rendering and input, my question mostly revolves around C and memory management. I wanted to post it here to get thoughts and insight into the approach, as I'm terrible when it comes to pointers.
Essentiall...
In the following code:
//anArray is a Array of Dictionary with 5 objs.
//here we init with the first
NSMutableDictionary *anMutableDict = [[NSMutableDictionary alloc] initWithDictionary:[anArray objectAtIndex:0]];
... use of anMutableDict ...
//then want to clear the MutableDict and assign the other dicts that was in the array of dic...
I was reading through 2010 CWE/SANS Top 25 Most Dangerous Programming Errors and one of the entries is for Buffer Copy without Checking Size of Input. It suggests using a language with features to prevent or mitigate this problem, and says:
For example, many languages that
perform their own memory management,
such as Java and Per...
I'm trying to see if I can find some leaks myself in Apple's TopSongs app. Can someone help me out in at least one and how to identify what is in the Leaks reports and how I can get an idea on finding them?
ie: I got one like this:
# Category Event Type Timestamp Address Size Responsible Library Responsible Caller
0 Gener...
I need help with deallocation of my NSMutableArray of custom objects. I need to retain the array and so I have added a property in .h and I release it in dealloc in .m file. When I add objects to the array, I do the following:
myarray = [[NSMutableArray alloc] init];
[myarray addObject:[[mycustomObject alloc]initWithObject:obj1]];
...
While running Instruments to find leaks in my code, after I've loaded a file and populate an NSMutableArray with new objects, leaks pop up! I am correctly releasing the objects. Sample code below:
//NSMutableArray declared as a retained property in the parent class
if(!mutableArray)
mutableArray = [[NSMutableArray alloc] initWi...
AFAIK, freeing a NULL pointer will result in nothing. I mean nothing is being done by the function free.
Still, I do see some statements where people say that one of the scenarios where memory corruption can occur is "freeing memory twice".
Is this still true?
...