Rép : NSHost class
Rép : NSHost class
- Subject: Rép : NSHost class
- From: joseph <email@hidden>
- Date: Sat, 17 Jul 2004 23:17:27 +0200
I have just tried what you suggested. I added this method to the
controller (a NSObject):
- (void)awakeFromNib
{
[NSHost setHostCacheEnabled:NO];
}
But unfortunatly, it's always the same. Here is a part of the doc :
"The NSHost class maintains a cache of previously created instances so
that requests for an existing NSHost return that object instead of
creating a new one. Use the setHostCacheEnabled: method to turn the
cache off, forcing lookup of hosts as theyre requested. You can also
use the flushHostCache method to clear the cache
of its entries so that subsequent requests look up the host information
and create new instances."
Actually, if seems that the method "currentHost" create an instance of
NSHost
the first time it is called and use it forever despite of the
"setHostCacheEnabled:NO"
and the "flushHostCache:" methods. I tell that because I have ran the
app using the ObjectAlloc tool.
When I look at the numbers Current, Peak and total of the NSHost
category, here is the behaviour :
The first time I push the button, I have 1 for all these numbers, wich
is quite normal (I wonder if
the current number should always be zero (1 for a very short duration)
? ). And this state remains the
same even if I ask to create a new instance of NSHost (I push the
button again).
If you have enought time, I think you could test that with ObjectAlloc,
even if you have an always-on connection.
And if you get the same results, and if I have well understood the
mecanism of memory allocation in cocoa,
it might be a problem of the NSHost class ???
thank you very much for you help,
joseph
SORRY FOR MULTIPLE RECEIVED
Le 17 juil. 04, ` 19:42, John C. Warner a icrit :
>
I have an always-on connection, so I can't test this, but what happens
>
if you setHostCacheEnabled:NO in your init/awakeFromNib code? Read the
>
docs about how the host cache relates to retained or existing NSHost
>
instances.
>
>
-John
>
>
On Jul 17, 2004, at 1:12 PM, joseph wrote:
>
>
> No this is a real IP address : 83.113.55.50 for instance
>
>
>
> joseph
>
>
>
>
>
> Le 17 juil. 04, ` 19:02, David Reed a icrit :
>
>
>
>> Is the IP you're getting 127.0.0.1? That's always assigned to your
>
>> Mac.
>
>>
>
>> David.
>
>>
>
>> On Saturday, Jul 17, 2004, at 11:56 US/Eastern, joseph wrote:
>
>>
>
>>> Hello,
>
>>>
>
>>> I try to get back the IP address of my computer using these lines of
>
>>> code :
>
>>>
>
>>>
>
>>> - (IBAction)GetIPAction:(id)sender
>
>>> {
>
>>> [NSHost flushHostCache];
>
>>> [IPTextFielOutlet setStringValue:[[NSHost currentHost] address]];
>
>>> }
>
>>>
>
>>>
>
>>> where "GetIPAction" is the method wich is lunched when a button is
>
>>> pressed
>
>>> and "IPTextFielOutlet" is a NSTextField instance.
>
>>>
>
>>> The first time I run the App. everything is OK : when I press the
>
>>> button
>
>>> the IP addres is displayed in the textfield.
>
>>>
>
>>> If I disconnect and then connect again my computer from the
>
>>> internet,
>
>>> getting
>
>>> another IP address, and then press the button once again, the IP
>
>>> address
>
>>> remains the same, even if it has realy changed.
>
>>>
>
>>> I am a beginner in MAC OS X and COCOA dev. So I'm sure that
>
>>> something is
>
>>> wrong in my code ... but I don't see where !!!
>
>>>
>
>>> Thanks a lot for your help,
>
>>> joseph
>
>>> _______________________________________________
>
>>> cocoa-dev mailing list | email@hidden
>
>>> Help/Unsubscribe/Archives:
>
>>> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
>>> Do not post admin requests to the list. They will be ignored.
>
>>>
>
>>>
>
>>
>
>> --
>
>> David Reed | email@hidden | AIM/iChat: parmadil01
>
> _______________________________________________
>
> cocoa-dev mailing list | email@hidden
>
> Help/Unsubscribe/Archives:
>
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.