Skip to content

Commit

Permalink
Try to address memory leak, looks to be in the JS
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee committed Apr 26, 2009
1 parent 1507555 commit 49ce497
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
2 changes: 0 additions & 2 deletions colloqueer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ sub irc_part {
my ($heap, $who, $to, $message) = @_[HEAP, ARG0, ARG1, ARG2];
my $nick = ( split /!/, $who )[0];
$message = "left" unless $message;
print STDERR "$to $nick $message\n";
return if $nick eq $heap->{app}->server->{nick};
return unless my $channel = $heap->{app}->channel_by_name($to);
my $event = Colloqueer::Event->new(
Expand All @@ -98,7 +97,6 @@ sub irc_quit {
my ($heap, $who, $message) = @_[HEAP, ARG0, ARG1];
my $nick = ( split /!/, $who )[0];
$message = "quit" unless $message;
print STDERR "$nick $message\n";
return if $nick eq $heap->{app}->server->{nick};
# my $event = Colloqueer::Event->new(
# nick => $nick,
Expand Down
10 changes: 7 additions & 3 deletions lib/Colloqueer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ sub BUILD {

open my $config_fh, '<', $self->config;
my $config = Load(join "\n", <$config_fh>);
close $config_fh;

%{ $self->{server} } = %{ $config->{server} };
$self->browser($config->{browser});
Expand All @@ -156,7 +157,7 @@ sub BUILD {

$self->window->add($self->notebook);
$self->window->show_all;
Glib::Timeout->add(50, sub { $self->display_messages });
Glib::Timeout->add(100, sub { $self->display_messages });
$self->notebook->signal_connect('switch-page', sub {$self->handle_switch_page(@_)});
$self->window->signal_connect('key-press-event', sub {$self->handle_window_keypress(@_)});
}
Expand All @@ -168,8 +169,10 @@ sub handle_switch_page {
$channel->entry->grab_focus;
return 0;
});
$channel->unread(0);
$channel->update_icon($channel->icons->{roomTab});
if ($channel->unread) {
$channel->unread(0);
$channel->update_icon($channel->icons->{roomTab});
}
}

sub handle_window_keypress {
Expand Down Expand Up @@ -286,4 +289,5 @@ sub unique_id {
return 'a' . $self->id_counter($self->id_counter + 1);
}

__PACKAGE__->meta->make_immutable;
1;
11 changes: 8 additions & 3 deletions lib/Colloqueer/Channel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use Glib qw/TRUE FALSE/;

has 'app' => (
isa => 'Colloqueer',
is => 'ro'
is => 'ro',
weak_ref => 1,
);

has 'name' => (
Expand Down Expand Up @@ -212,8 +213,8 @@ sub handle_input {
my $msg = Colloqueer::Message->new(
app => $self->app,
channel => $self,
nick => $self->app->server->nick,
hostmask => $self->app->server->nick."!localhost",
nick => $self->app->server->{nick},
hostmask => $self->app->server->{nick}."!localhost",
text => $string,
);
push @{$self->msgs}, $msg;
Expand Down Expand Up @@ -244,6 +245,7 @@ sub add_event {

sub clear_events {
my ($self, $msg) = @_;
$_ = undef for @{$self->events};
$self->events([]);
}

Expand Down Expand Up @@ -285,6 +287,7 @@ sub display_message {
my $consecutive = 1 if $msg->nick eq $self->lastnick and ! $self->cleared;
$self->lastnick($msg->nick);
$html = $self->app->format_messages($consecutive, $msg);
$msg = undef;
$self->cleared(0);
if (! $self->focused) {
$self->unread(1);
Expand All @@ -302,4 +305,6 @@ sub display_message {
$self->webview->execute_script("document.title='$html';");
}

__PACKAGE__->meta->make_immutable;

1;
4 changes: 3 additions & 1 deletion lib/Colloqueer/Event.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package Colloqueer::Event;
use Moose;
use Colloqueer::Channel;
use MIME::Base64 qw/encode_base64/;

has 'nick' => (
isa => 'Str',
Expand All @@ -23,6 +22,7 @@ has 'message' => (
has 'channel' => (
isa => 'Colloqueer::Channel',
is => 'ro',
weak_ref => 1,
required => 1
);

Expand All @@ -42,4 +42,6 @@ has 'id' => (
}
);

__PACKAGE__->meta->make_immutable;

1;
4 changes: 2 additions & 2 deletions lib/Colloqueer/Message.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package Colloqueer::Message;
use Moose;
use Colloqueer::Channel;
use DateTime;
use MIME::Base64 qw/encode_base64/;
use IPC::Open2;

has 'nick' => (isa => 'Str', is => 'ro', required => 1);
has 'hostmask' => (isa => 'Str', is => 'ro', required => 1);
has 'consecutive' => (isa => 'Bool', is => 'rw');
has 'channel' => (isa => 'Colloqueer::Channel', is => 'ro', required => 1);
has 'channel' => (isa => 'Colloqueer::Channel', is => 'ro', required => 1, weak_ref => 1);
has 'time' => (isa => 'DateTime', is => 'ro', default => sub { DateTime->now });
has 'text' => (isa => 'Str', is => 'ro', required => 1);
has 'id' => (isa => 'Str', is => 'ro', lazy => 1, default => sub {
Expand Down Expand Up @@ -36,4 +35,5 @@ has 'html' => (isa => 'Str', is => 'ro', lazy => 1, default => sub {
return $string;
});

__PACKAGE__->meta->make_immutable;
1;
6 changes: 4 additions & 2 deletions share/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<script type="text/javascript">
document.title = '__empty__';
scrollToBottom();
function monitorTitle () {
monitorTitle = function () {
if (document.title != '__empty__') {
var html = document.title;
document.title = '__empty__';
Expand All @@ -62,13 +62,15 @@
if (msg[msg.length - 1]) {
msg[msg.length - 1].parentNode.innerHTML += html;
}
msg = undefined;
}
else {
container.innerHTML += html;
}
html = undefined;
scrollToBottom();
}
setTimeout(monitorTitle, 50);
setTimeout(monitorTitle, 100);
}
monitorTitle();
</script>
Expand Down

0 comments on commit 49ce497

Please sign in to comment.