By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Python 3.3 urllib memory leakage

P: 2
Im using mac mini with ios 10.9.2 and Python 3.3. I wrote simple Python app, which fetch api data and shows some calculation. Everything is working well, but i saw in Activity Monitor (os tool) that after few connections system memory usage incrases, but in my opinion it shouldnt. I wouldnt publish aplication that can eat all memory so I need a help.

Here is a pice of my code which makes this problem:

Expand|Select|Wrap|Line Numbers
  1. import urllib.request
  2. import time
  3.  
  4. class Main(object):
  5.     def Get(self, url):
  6.         urlData = urllib.request.urlopen(url)
  7.         for line in urlData:
  8.             line = str(line,'utf-8')
  9.             print( line.rstrip() )
  10.         urlData.close()
  11.         time.sleep(1)
  12.  
  13. M = Main()
  14. url = "https://btc-e.com/api/2/btc_usd/trades"
  15. b=1
  16.  
  17. while b>0:
  18.     M.Get(url)
  19.  
I tried to do in another way but it makes memory usage incrasing too:

Expand|Select|Wrap|Line Numbers
  1. req = request.urlopen('https://btc-e.com/api/2/btc_usd/trades')
  2. urlData = json.loads(req.read().decode('utf-8')) 
This makes memory usage higher too:

Expand|Select|Wrap|Line Numbers
  1. from urllib.request import urlopen
  2. html = urlopen("https://btc-e.com/api/2/btc_usd/trades")
Thank you in advance!
Apr 17 '14 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 614
This question is better asked on a Mac forum where people know more about the OS than us. The short answer is it depends on which program you are using to display memory usage. Does it display real usage or shared memory usage. Also, the Mac OS is related to Linux in some way, and Linux allocates all the memory that a program might ever use, when the memory is available, and so some tools would report a lot of memory "used" even though that memory is just waiting there and is available for other programs.
Apr 17 '14 #2

P: 2
Thank You for answer.

I will check memory usage with other tool.
Is there any python 3.3 tool to check if memory was relased?
Apr 18 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.