I am calling [array addObjectsFromArray:dictionary.allValues]
Will each copied object have retain count incremented for it?
My understanding that when I do [array addObject:obj] , it will retain obj for me untill I delete obj from array or release array itself. Was wondering if its the same with addObjectsFromArray
Thanks.
refer this :
NSMutableArray memory management
Regarding the object creation methods, all of the convenience methods (array:, arrayWithObjects:, arrayWithArray:, etc.) return autoreleased objects. However, their corresponding init methods (init:, initWithObjects:, initWithArray:, etc.) do not - if you call them, you are responsible for calling release on the returned object
function that begin with init,copy,add etc always increments the retain counter of the corresponding object.If you are done with and object you should release it adterr adding to an nsmutablearray
Related
When I update a NSManagedObject and save it, I get an error: The operation couldn’t be completed. (Cocoa error 1560.)
the object is already in the database, so in fact I am doing an update when saving it
when I save the object prior to modifying it, no error
I modify it by setting a property of the object. Using KVP has the same result
the original save (the object has been created shortly before) and saving after the update are done all in the main thread. The object is never touched from another thread.
The method validateForUpdate: always returns NO. I am not sure if this method should return YES even if the object has not been changed: if object X is saved without error and then I call validateForUpdate: it returns NO.
Any ideas?
The property you change has constraints on what its value could be. Your update violates them, hence keeping you from persisting invalid changes.
Node.js will do auto garbage collections ?
var objUser = new Object ();
objUser.userName = objReq.userName;
userDB.registerUser (objUser , callback) ;
In the above code I have "objUser" which will be passed as an argument to another class and it is no longer required in the present class. Still, should I have to forcefully collect it or will it do automatically.
To do it manually, Will NULL help or is there any other mechanism given by Node Framework?
objUser = null;
Node does garbage collection, but if userDb.registerUser() retains a reference to it, your objUser will not be collected. Only when no references to an object remain it will be collected. You usually don't need to explicitly release local references by assigning null to the variable — when your function returns, all local references are released automatically. You need to worry only about global references to your object.
Also worth noting on this subject: It's been my experience that objects of the same type will reuse instances. So, if you truly want a "new Instance()" of an object make sure you nullify or reset any attributes in your constructors
I have just declared an NSString Object without using alloc and init methods. After that i added the string to this newly created string Object, it is working fine , why?
Code:
NSString *str;
str=#"Adding the data without allocating and initilizing object";
NSLog(#"%#",str);
The #"some string" method already creates a constant NSString for you. You created a pointer to a string in your first line and assigning it to point to newly created constant string in a second line.. This way is very common. Actually there are almost no cases you really need to call alloc, init on NSString.
I'm using db4o with groovy (actually griffon). I'm saving dozen of objects into db4o objectSet and see that .yarv file size is about 11Mb. I've checked its content and found that it stores metaClass with all nested fields into every object. It's a waste of space.
Looking for the way to avoid storing of metaClass and therefore reduce the size of result .yarv file, since I'm going to use db4o to store millions of entities.
Should I try callConstructors(true) db4o configuration? Think it would help?
Any help would be highly appreciated.
As an alternative you can just store 'Groovy'-beans instances. Those are compiled down to regular Java-ish classes with no special Groovy specific code attached to them.
Just like this:
class Customer {
// properties
Integer id
String name
Address address
}
class Address{
String street;
}
def customer = new Customer(id:1, name:"Gromit", address:new Address(street:"Fun"))
I don't know groovy but based on your description every groovy object carries metadata and you want to skip storing these objects.
If that is the case installing a "null translator" (TNull class) will cause the "translated" objects to not be stored.
PS: Call Constructor configuration has no effect on what gets stored in the db; it only affects how objects are instantiated when reading from db.
Hope this helps
I know that
detachNewThreadSelector:toTarget:withObject
can have a (id)anArgument. I have searched it that it can work for NSString.
However, when I pass an integer or size_t, it crashed. Can somebody tell me what is (id)anArgument?
What's more, how can I pass more than one parameter to the thread? For example, I have a function,
-(NSInteger)getIneger: (NSInteger) pageNumber withName(NSString*) filename ;
something like that.
Thanks
What (id)anArgument tells you is that you need to pass an Objective-C argument. Since neither integer nor size_t are Objective-C objects, the application crashes. You will need to package them within an NSNumber for this to work. You will also have to alter the method to take in an NSNumber rather than the int. To pass two or more arguments, I suggest you use an NSDictionary object to pass values based on keys. You can define a method that takes in an NSDictionary object, unpacks the values and calls the original method you had intended to call.