memory-deallocation

Freeing CUDA memory painfully slow

I am allocating some float arrays (pretty large, ie 9,000,000 elements) on the GPU using cudaMalloc((void**)&(storage->data), size * sizeof(float)). In the end of my program, I free this memory using cudaFree(storage->data);. The problem is that the first deallocation is really slow, around 10 seconds, whereas the others are nearly inst...

QList memory deallocation

I'm trying to free memory after using QList, but it doesn't seem to work properly. Here's my code: QList<double> * myList; myList = new QList<double>; double myNumber; cout << "CP1" << endl; getchar(); // checkpoint 1 for (int i=0; i<1000000; i++) { myNumber = i; myList->append(myNumber); cout << myList->size() << endl; ...

Deallocating NSMutableArray of custom objects

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]]; ...

Does it take time to deallocate memory?

I have a C++ program which, during execution, will allocate about 3-8Gb of memory to store a hash table (I use tr1/unordered_map) and various other data structures. However, at the end of execution, there will be a long pause before returning to shell. For example, at the very end of my main function I have std::cout << "End of execut...

Core Data - How to check if a managed object's properties have been deallocated?

I've created a program that uses core data and it works beautifully. I've since attempted to move all my core data methods calls and fetch routines into a class that is self contained. My main program then instantiates that class and makes some basic method calls into that class, and the class then does all the core data stuff behind t...

dealloc properties with assign and readwrite objective-c

I have this structure: @interface MyList : NSObject { NSString* operation; NSString* link; } @property (readwrite) NSString* operation; @property (readwrite, assign) NSString* link; @end @implementation MyList @synthesize operation,link; @end I know that if I had retain instead of readwrite I should release the operation ...

"Right" way to deallocate an std::vector object

The first solution is: std::vector<int> *vec = new std::vector<int>; assert(vec != NULL); // ... delete vec; An alternative is: std::vector<int> v; //... vec.clear(); vec.swap(std::vector<int>(vec)); The second solution's a bit of a trick --- what's the "right" way to do it? Update: I'm aware that the destructor will be called on...

Can I catch bad pointer errors in C++?

Hi there, I was wondering if there is a possibility to catch errors like this in C++: object* p = new object; delete p; delete p; //this would cause an error, can I catch this? Can I check if the pointer is valid? Can I catch some exception? I know I could set the pointer p to NULL after the first object deletion. But just imagin...

[NSCustomView isOpaque]: message sent to deallocated instance 0x123456

Hi all I receive that message in debugger console since I added the following arguments for debugging my application with XCode. NSZombieEnabled: YES NSZombieLevel: 16 I was looking for zombie objects... Before doing so, the application failed before I could know where what and why was happening.... Now I´m pretty sure that 'something...

Time for deleting pointers

Hei community, I've got a small question concerning the deletion of pointers. I am working with pointer-to-pointer matrices of Dimension 1024x1024. Since I am creating them dynamically, I delete the allocated space for them at the end of the program. But doing this in the usual loop costs quite a lot of time - I measured about 2sec usi...

memory management

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 ...

-[ClassRoster controllerWillChangeContent:]: message sent to deallocated instance

I know these errors are very app-specific and almost always due to over-releasing an object. I just can't spot it and the debugging tips I have read haven't done the trick for me yet. According to this debugging advice, my "offending object" was allocated in this code block (located in AddClass.m): - (void)tableView:(UITableView *)tab...

What is the purpose of the second parameter to std::allocator<T>::deallocate?

In here is declaration of deallocate mem. of allocator class. My question is what for is second argument in this declaration? If this function calls operator delete(_Ptr) this argument is unused so what's for is it there? Thanks. Excerpt from MSDN: Frees a specified number of objects from storage beginning at a specified position. voi...

How to deallocate memory in prefix tree? (ANSI C)

I tried to deallocate memory in dict_free() function, but it doesn't work and I don't no why. Am I missing something? Can't figure out, what's wrong. Edit: If I call free() in dict_free() I expect to see that free'd pointer points to NULL, but that's not happening. Here is my code: #include <stdio.h> #include <stdlib.h> #include <stri...

C++ Deallocating objects stored in a vector

I have a class that creates a vector of objects. In the deconstructor for this class I'm trying to deallocate the memory assigned to the objects. I'm trying to do this by just looping through the vector. So, if the vector is called maps I'm doing: Building::~Building() { int i; for (i=0; i<maps.size(); i++) { delete[] &m...